• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

DollarFormat rounding problem?

New Here ,
Oct 10, 2017 Oct 10, 2017

Copy link to clipboard

Copied

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!

Views

613

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Oct 10, 2017 Oct 10, 2017

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

Votes

Translate

Translate
Explorer ,
Oct 10, 2017 Oct 10, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 10, 2017 Oct 10, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 10, 2017 Oct 10, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 10, 2017 Oct 10, 2017

Copy link to clipboard

Copied

I'll send it over.  I think I see a link to do it in the email your response sent.  Thank you again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 11, 2017 Oct 11, 2017

Copy link to clipboard

Copied

LATEST

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation