MikeMcl / bignumber.js

A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic
http://mikemcl.github.io/bignumber.js
MIT License
6.69k stars 742 forks source link

Is there any way to disable "groupSeparator" #182

Closed Argun closed 6 years ago

Argun commented 6 years ago

The default groupSeparator is "," Is there any way to disable groupSeparator? I change the groupSeparator to empty string but it doesn't work.

MikeMcl commented 6 years ago

You can either set groupSeparator to the empty string or set groupSize to zero.

I suspect you are trying

BigNumber.set({FORMAT: {groupSeparator: ''})

but that will mean that the values for the other format properties are lost. To avoid this, even if you want to change only one format property, an object with all the format properties you need must be passed.

Alternatively, change individual properties by using a reference to the passed format object as shown below.

// default values
format = {
  decimalSeparator: '.',
  groupSeparator: ',',
  groupSize: 3,
  secondaryGroupSize: 0,
  fractionGroupSeparator: ' ',
  fractionGroupSize: 0
}
BigNumber.set({ FORMAT: format })

x = new BigNumber('123456789.123456789')
x.toFormat()                    // '123,456,789.123456789'

format.groupSeparator = ''
x.toFormat()                    // '123456789.123456789'

format.groupSeparator = ','
x.toFormat()                    // '123,456,789.123456789'

format.groupSize = 0
x.toFormat()                    // '123456789.123456789'

See toFormat.