Skip to main content
Participating Frequently
Oct 10, 2017 7:38 PM UTC
Answered

DollarFormat rounding problem?

DollarFormat(1214.225) is returning $1,214.22.  I would expect $1,214.23.  I think I would have noticed this before and I am wondering if it a CF2016 issue or is this the normal behavior.

Thanks!

This topic is closed to new replies. Start a new post to keep the conversation going.
Grae  Desmond
Grae DesmondCorrect answer
Inspiring
Oct 10, 2017 8:23 PM UTC

I was being lazy and just copied and pasted the original example.  Should've played more.  Strange it would work by adding another decimal place.  Definitely a bug.  Are you going to submit it?  If not i can add.

Tracker

5 replies

James Moberg
Inspiring
Oct 11, 2017 1:40 PM UTC

If you want better rounding with finer grain mods for up, down and even rounding, consider using the decimalRound UDF. After rounding, prepend the cosmetic $ symbol and use NumberFormat().
http://cflib.org/udf/decimalRound

You could create your own UDF to leverage this:

<cfscript>
function DollarFormat2(num){
if (val(num) GT 0){
return "$" & trim(NumberFormat(decimalRound(num, 2, "up"), '999,999,999,999.00'));
} else {
return "-$" & trim(replace(NumberFormat(decimalRound(num, 2, "up"), '999,999,999,999.00'),'-',''));
}
}
</cfscript>

Translate
Grae  Desmond
Inspiring
Oct 10, 2017 7:57 PM UTC

Using Trycf.com and choosing various CF flavors it seems this is normal across versions.  So it seems they expect you to round it then format it.

Translate
EBG1103Author
Participating Frequently
Oct 10, 2017 8:03 PM UTC

Thank you.  DollarFormat(1214.2251) does return $1,214.23.  Seems like a bug to me since it is rounding.

Translate
Grae  Desmond
Grae DesmondCorrect answer
Inspiring
Oct 10, 2017 8:23 PM UTC

I was being lazy and just copied and pasted the original example.  Should've played more.  Strange it would work by adding another decimal place.  Definitely a bug.  Are you going to submit it?  If not i can add.

Tracker

Translate