@@ -4838,12 +4838,26 @@ func format(value, numFmt string, date1904 bool, cellType CellType, opts *Option
48384838
48394839// getNumberPartLen returns the length of integer and fraction parts for the
48404840// numeric.
4841- func getNumberPartLen (n float64 ) (int , int ) {
4842- parts := strings .Split (strconv .FormatFloat (math .Abs (n ), 'f' , - 1 , 64 ), "." )
4841+ func (nf * numberFormat ) getNumberPartLen () (int , int ) {
4842+ var intPart , fracPart , intLen , fracLen int
4843+ parts := strings .Split (strconv .FormatFloat (math .Abs (nf .number ), 'f' , - 1 , 64 ), "." )
4844+ intPart = len (parts [0 ])
48434845 if len (parts ) == 2 {
4844- return len ( parts [ 0 ]), len (parts [1 ])
4846+ fracPart = len (parts [1 ])
48454847 }
4846- return len (parts [0 ]), 0
4848+ if nf .intHolder > intPart {
4849+ nf .intHolder = intPart
4850+ }
4851+ if intLen = intPart ; nf .intPadding + nf .intHolder > intPart {
4852+ intLen = nf .intPadding + nf .intHolder
4853+ }
4854+ if fracLen = fracPart ; fracPart > nf .fracHolder + nf .fracPadding {
4855+ fracLen = nf .fracHolder + nf .fracPadding
4856+ }
4857+ if nf .fracPadding > fracPart {
4858+ fracLen = nf .fracPadding
4859+ }
4860+ return intLen , fracLen
48474861}
48484862
48494863// getNumberFmtConf generate the number format padding and placeholder
@@ -5021,25 +5035,12 @@ func (nf *numberFormat) printBigNumber(decimal float64, fracLen int) string {
50215035// numberHandler handling number format expression for positive and negative
50225036// numeric.
50235037func (nf * numberFormat ) numberHandler () string {
5038+ nf .getNumberFmtConf ()
50245039 var (
5025- num = nf .number
5026- intPart , fracPart = getNumberPartLen (nf .number )
5027- intLen , fracLen int
5028- result string
5040+ num = nf .number
5041+ intLen , fracLen = nf .getNumberPartLen ()
5042+ result string
50295043 )
5030- nf .getNumberFmtConf ()
5031- if nf .intHolder > intPart {
5032- nf .intHolder = intPart
5033- }
5034- if intLen = intPart ; nf .intPadding + nf .intHolder > intPart {
5035- intLen = nf .intPadding + nf .intHolder
5036- }
5037- if fracLen = fracPart ; fracPart > nf .fracHolder + nf .fracPadding {
5038- fracLen = nf .fracHolder + nf .fracPadding
5039- }
5040- if nf .fracPadding > fracPart {
5041- fracLen = nf .fracPadding
5042- }
50435044 if isNum , precision , decimal := isNumeric (nf .value ); isNum {
50445045 if precision > 15 && intLen + fracLen > 15 && ! nf .useScientificNotation {
50455046 return nf .printNumberLiteral (nf .printBigNumber (decimal , fracLen ))
@@ -5062,6 +5063,10 @@ func (nf *numberFormat) numberHandler() string {
50625063 if nf .useFraction {
50635064 num = math .Floor (math .Abs (num ))
50645065 }
5066+ if ! nf .useScientificNotation {
5067+ ratio := math .Pow (10 , float64 (fracLen ))
5068+ num = math .Round (num * ratio ) / ratio
5069+ }
50655070 if result = fmt .Sprintf (fmtCode , math .Abs (num )); nf .useCommaSep {
50665071 result = printCommaSep (result )
50675072 }
0 commit comments