Formatting Currency

Hi All,

I’m grabbing some numbers from a database and then working out percentages of them (like this)


The problem is that i’m now getting 3-* decimal places showing (eg. $8262.554999999998)

The number that comes out of the database only shows 2 decimal places (which is what I want). I can’t for the life of me work out what I’m doing wrong.

Any guidance would be greatly appreciated :slight_smile:

Thanks again,

I’m a total newbie so this is likely not going to help but I have gotten so much help here I’m going to try…

Forgive me if I’m way out in left field.

I was having a problem like that a few weeks ago and it turned out to be cause by placing my .round(2) on the wrong side of a parentheses or missing a parentheses, I can’t remember and of course I did not take notes :frowning:

Hope it helps and good luck!

Hi norcoscia,

Thanks for reaching out :smiley: I was actually looking over the source of your site trying to work out how to do it haha. Still haven’t figured it out (i’m guessing I am missing a bracket or something) - I have fiddled with the position of .round(2) however that doesnt seem to fix it, I know the data formatter has an option to format currency but when I do that it seems to just show nothing. I’ll keep fiddling :slight_smile:


1 Like

Thanks Ben, BTW, my site would not exist if it was not for the help @drymetal provided (and a ton of it)…

I’m fiddling away here too, since about 4AM trying to get stuff lined up - I sure wish tabs existed in the world of HTML :slight_smile:

haha! This community really is great with all of the help that people give out!
It’s 1:55AM here and I’m still going too! :smiley:

1 Like

Have you tried this?
{{[0].grandtotal.formatCurrency("$", “.”, “,”, “2”)}}

Hi turn3636,

yep that works fine but as soon as I try to multiply it breaks.

There’s nothing wrong with the number that this spits out: {{[0].grandtotal.toNumber()}}

It’s just as soon as I stick *0.30 (to get 30% of the original number) that it goes crazy with decimal places.

At the very end, put .round(2) and that will limit the decimals. You can also use toFixed(2), but that will convert it into a string. However if you are just printing this out on the page, it doesn’t matter if it is a string or number if you aren’t referencing it anywhere.

So you could do something like this:

{{"$" + ([0].grandtotal * 0.3).round(2)}} (Assuming that what is coming here is a number)
{{"$" + ([0].grandtotal * 0.3).toFixed(2)}}

drymetal, thank you very very much.

the first suggestion

worked perfectly.


1 Like

You should be able to insert the .formatcurrency instead of the .todecimal if you want the $ symbol and not just the decimal, but if what you have is working fine, great. Always more than one way to do it!


If you really had a need to use the formatCurrency it would work even with the * 3 as long as it is at the very end like this

{{([0].grandtotal.toNumber()*0.3).formatCurrency("$", “.”, “,”, “2”)}}
This way you are getting the full number output first and then formatting the returned number into the currency formatter, in my opinion this should work, or just stick with the round solution as it also works, up to you.

1 Like

Yes, what @psweb said. That’s what I was trying to say but that’s what i get for typing on my mobile without my reading glasses, plus he just explained it better. Also I incorrectly type .todecimal instead of .tonumber. I use the currency formatting a lot, even in calculations like you are using and as long as it is at the end, it should work. Again, more than one way to make it work but if you are trying to show currency, the currency formatting is the best way as it rounds and places the $ sign as well as all the comas.

1 Like