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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

How to return a number with commas?


Go to End


2 Posts   853 Views

Avatar
digibrains

Community Member, 130 Posts

11 February 2015 at 10:53am

I'm trying to input a number like...12345678 and in my template return something like 12,345,678.

I'm using 'Float' as the db type and using the Nice() method.

private static $db = array(
        'MyNum' => 'Float'
    );

<div class="content">
    <h1>$Title</h1>
    <p>$MyNum.Nice</p>
    ....

But it's rounding so I'm getting this instead:
12,345,700

I guess I could just use Varchar(n) instead of Float, but that just seems wrong. How do I get the actual number?

Avatar
thomas.paulson

Community Member, 107 Posts

12 February 2015 at 5:14pm

Hi

Use 'Double' instead of Float,

private static $db = array(
'MyNum' => 'Double'
);

Double variable can store large number, than Float.