Ritu
Ritu

Reputation: 1105

Coldfusion number format

I have a code like this :

 <cfset n = '222222222222222'>
 <cfset sum=0>
 <cfset sum +=  n>
<cfoutput>#sum#</cfoutput>

The output is :

2.22222222222E+014 

Is there any way I can get output in normal form as '222222222222222' ?

Upvotes: 1

Views: 512

Answers (2)

Tushar Bhaware
Tushar Bhaware

Reputation: 2525

The value of n is 222222222222222. It's a big integer. To perform arithmatic operation on big integer, you need precision evaluate function. Your code should be as below:

<cfset n = '222222222222222'>
<cfset sum=0>
<cfset sum = precisionEvaluate(sum + n)>
<cfoutput>#sum#</cfoutput>

Upvotes: 5

Kaymaz
Kaymaz

Reputation: 486

A possible solution (works with the given example): CF Doc - NumberFormat

#NumberFormat(sum, '9')#

Upvotes: 2

Related Questions