Flex grid - number formatting without trailing zeros

Posted by: rasika.sinha on 12 September 2017, 9:31 pm EST

  • Posted 12 September 2017, 9:31 pm EST

    Hi Team,

    I need to remove the trailing zeros from few of the columns in my grid. Some of them have currency formatting ‘c’ and others have number formatting ‘n’.

    I have seen that there is a ‘g’ General (no trailing zeros) format but it will not solve my issue as the comma separation and $ prefix would get lost in the general formatting. There is also a function formatNumber inside globalize class which has this feature but i don’t want to call this method in my itemFormatter for each column.

    Can you please help me identify a way to remove trailing zeros by setting up the format of my column such that the comma separation and currency prefix formatting is retained?

    Thanks,

    Rasika.

  • Posted 13 September 2017, 9:03 pm EST

    Hi Rasika,

    You need to use the formatNumer method in itemFormatter for removing trailing zeros.

    Thanks,

    Manish Kumar Gupta

  • Posted 16 January 2020, 10:28 am EST

    Hi GrapeCity,

    Could you post an example of removing the decimals from a currency column via formatNumber, as Manish mentions above in his answer?

    Specifically, keeping the $ sign via ‘currency’ format but without decimals.

  • Posted 16 January 2020, 5:35 pm EST

    Hi Kyle,

    If you are not using the ‘g’ format on the column on which you need to apply the currency format, then you can simply set the format property of that particular column to ‘c0’.

    But, if you are, then you will need to use the formatItem event and in this event, use the formatNumber method to convert the value to ‘c0’ format. Please refer to the sample below for reference:

    https://stackblitz.com/edit/js-lmown6

    In this sample, the ‘sales’ column is formatted using the format property and the ‘expenses’ column is formatted using formatNumber method.

    Regards,

    Ashwin

Need extra support?

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

Learn More

Forum Channels