Globalize.format custom numeric strings

Posted by: kamil.zainal.abidin on 18 October 2020, 8:55 pm EST

  • Posted 18 October 2020, 8:55 pm EST


    I'm looking to do a custom numeric format for accounting where negative numbers are encapsulated in brackets, amongst other things:
    -1234.567 -> (1,234.57)

    Looking at the documentation I can see that Globalize.format is based off
    As far as I can tell, the library is capable of adding in the appropriate formatting for commas and decimal places, but there isn't any way to handle negative values enclosed in brackets.

    Is there any functionality similar to, or would I need to write a custom formatter to handle this?

    Many thanks
  • Marked as Answer

    Replied 19 October 2020, 10:37 pm EST

    Hello Kamil,
    The specified bracket format gets applied for currency format. This format can be changed as you would like by modifying the wijmo.culture. Please refer to the following code snippet and the fiddle sample for reference:

    Hope it helps!

    Manish Gupta
  • Replied 21 October 2020, 3:44 am EST


    Thanks for pointing out how we can change the pattern for currency - that definitely helped me sort out the negative and currency formats.

    One more question regarding the Globalize formats though. The docs state that the g general format uses the .NET numeric format strings. But it seems to me that adding the precision value doesn't actually format it to 15 significant digits, but instead makes it to 15 decimal places (see

    I understand that the library probably doesn't intend to copy the exact functionality done in the .NET formatter, so is there any easy way for me to override this functionality so I can make the 'g15' format to actually format a number to 15 significant digits?

    Many thanks
  • Replied 21 October 2020, 11:19 pm EST


    As stated in the following doc:
    The number format in wijmo takes the "Axxsscc" form where "xx" xx is an optional integer called precision specifier.
    I understand that the confusion is arised from the fact that the docs mentioned that format accept the .NET-style Standard Numeric Format Strings. But it is just for the A part in the above-mentioned form. Actual functionality could be a little different.
    Further, I've asked the dev team to confirm if this is actually the excepted behavior or is it a bug(#467575). I will update you as soon as I hear back from the team.

    Regarding overriding the g formatter, you would have to override the Globalize.formatNumber method and return the required result for the 'g' formatter.

  • Replied 25 October 2020, 9:49 pm EST


    Thanks for the clarification on the docs and pointing out the method to override.
    I look forward to finding out if it's as intended, but I suppose it's consistent with the other formats in treating 'xx' as the number of decimal points to show.

  • Replied 26 October 2020, 8:10 pm EST


    The dev team has confirmed that it is by design and is consistent with other formats too.

  • Replied 2 November 2020, 9:03 pm EST

    Aha, okay. Thanks for the update.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels