Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ColdFusion, is there a numberFormat() mask to drop the decimal if it is 0?

I'm trying to format numbers so that 2 decimal places show up, unless it is a whole number - then I don't want a decimal point to show. I've tried 0.00, _.__, 9.99 and several combinations. Is there a mask for the numberFormat function that can get this result?

like image 702
eterps Avatar asked Jul 05 '12 19:07

eterps


2 Answers

<cfif int(x) eq x>
  #int(x)#
<cfelse>
  #DecimalFormat(x)#
</cfif>
like image 188
Henry Avatar answered Sep 19 '22 10:09

Henry


You could divide the variable by 1 and then the whole number is shown without a decimal place.

<cfset a = 5.00>
<cfset b = 5.55>

<cfoutput>#a/1#, #b/1#</cfoutput>

Output is 5, 5.55. Instead of 5.00, 5.55 if you don't divide by 1.

like image 29
Jason M Avatar answered Sep 23 '22 10:09

Jason M