Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Show formated Number With , for decimals '.' per thousand,.. like CMS NumericField does


Go to End


3 Posts   2038 Views

Avatar
Lukin

Community Member, 56 Posts

20 April 2017 at 6:24am

Edited: 20/04/2017 6:25am

Hello,

Id iike to show my numbers like they are shown in the backend using NumericField. Is there a way to get that without string-manipulation?

Thanks in advance and best wishes
Fabian

Avatar
ZarockNZ

Community Member, 17 Posts

21 April 2017 at 4:14pm

Edited: 21/04/2017 4:15pm

Hi,

When outputting a decimal number in a template you can use the .Nice function to format the number.

For example: $MyDecimalNumber.Nice

Int numbers have a .Formatted function which does a similar thing, example: $MyIntNumber.Formatted

Both of these will add the thousands separator and for decimals the decimal point will be included too.

Regards,
DouG.

Avatar
Lukin

Community Member, 56 Posts

24 April 2017 at 11:51pm

Hej DouG,

thanks a lot ;)

Regards,
Fabian