@@ -4838,12 +4838,26 @@ func format(value, numFmt string, date1904 bool, cellType CellType, opts *Option
4838
4838
4839
4839
// getNumberPartLen returns the length of integer and fraction parts for the
4840
4840
// 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 ])
4843
4845
if len (parts ) == 2 {
4844
- return len ( parts [ 0 ]), len (parts [1 ])
4846
+ fracPart = len (parts [1 ])
4845
4847
}
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
4847
4861
}
4848
4862
4849
4863
// getNumberFmtConf generate the number format padding and placeholder
@@ -5021,25 +5035,12 @@ func (nf *numberFormat) printBigNumber(decimal float64, fracLen int) string {
5021
5035
// numberHandler handling number format expression for positive and negative
5022
5036
// numeric.
5023
5037
func (nf * numberFormat ) numberHandler () string {
5038
+ nf .getNumberFmtConf ()
5024
5039
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
5029
5043
)
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
- }
5043
5044
if isNum , precision , decimal := isNumeric (nf .value ); isNum {
5044
5045
if precision > 15 && intLen + fracLen > 15 && ! nf .useScientificNotation {
5045
5046
return nf .printNumberLiteral (nf .printBigNumber (decimal , fracLen ))
@@ -5062,6 +5063,10 @@ func (nf *numberFormat) numberHandler() string {
5062
5063
if nf .useFraction {
5063
5064
num = math .Floor (math .Abs (num ))
5064
5065
}
5066
+ if ! nf .useScientificNotation {
5067
+ ratio := math .Pow (10 , float64 (fracLen ))
5068
+ num = math .Round (num * ratio ) / ratio
5069
+ }
5065
5070
if result = fmt .Sprintf (fmtCode , math .Abs (num )); nf .useCommaSep {
5066
5071
result = printCommaSep (result )
5067
5072
}
0 commit comments