Skip to main content
Inspiring
April 14, 2010
Answered

Need help getting the digits without the decimal

  • April 14, 2010
  • 2 replies
  • 648 views

I have a number such as 6711.00425532 , how can I get the 6711 without rounding this number up or down. In another words, I don't care with any number after the period, all I need is whatever the number before the period, as is.

If the number is 23.02345,  I need to get just the 23

If the number is 344.985430,  I need just the 344

Is this possible?

This topic has been closed for replies.
Correct answer BKBK

BYJ_wntrsnt wrote:

I have a number such as 6711.00425532 , how can I get the 6711 without rounding this number up or down. In another words, I don't care with any number after the period, all I need is whatever the number before the period, as is.

If the number is 23.02345,  I need to get just the 23

If the number is 344.985430,  I need just the 344

Is this possible?

Fix it.

<cfoutput>
fix(6711.00425532): #fix(6711.00425532)#<br>
fix(23.02345): #fix(23.02345)#<br>
fix(344.985430): #fix(344.985430)#<br>
fix(-6711.00425532): #fix(-6711.00425532)#<br>
fix(-23.02345): #fix(-23.02345)#<br>
fix(-344.985430): #fix(-344.985430)#<br>
</cfoutput>

2 replies

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
April 15, 2010

BYJ_wntrsnt wrote:

I have a number such as 6711.00425532 , how can I get the 6711 without rounding this number up or down. In another words, I don't care with any number after the period, all I need is whatever the number before the period, as is.

If the number is 23.02345,  I need to get just the 23

If the number is 344.985430,  I need just the 344

Is this possible?

Fix it.

<cfoutput>
fix(6711.00425532): #fix(6711.00425532)#<br>
fix(23.02345): #fix(23.02345)#<br>
fix(344.985430): #fix(344.985430)#<br>
fix(-6711.00425532): #fix(-6711.00425532)#<br>
fix(-23.02345): #fix(-23.02345)#<br>
fix(-344.985430): #fix(-344.985430)#<br>
</cfoutput>

Inspiring
April 15, 2010

I think fix() is the best suggestion out of the ones offered.

CF's implementation of int() has a bug with negative numbers, in that it does not simplyu return the integer portion of the number (as it should), it returns the next lower integer.  This works fine for positive numbers, but it one out for negative numbers, eg: int(-1.23) = -2.  fix() is the fix for this.

Using listFirst() seems to be trying to use a square peg to fill a round hole to me.  It'll work, but it's a misuse of the function, IMO: 3.1415 is not a list, it's a number.

I second Ian's comment about reading the docs, btw.

--

Adam

ilssac
Inspiring
April 14, 2010
<cfoutput>#int(6711.00425532)#</cfoutput>

It can be quite enlightening when one just peruses the documentation from time to time.

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_14.html

Inspiring
April 14, 2010

ListFirst will also work.  Nice to have choices.

ilssac
Inspiring
April 14, 2010

To augment Dan's reply. 

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_13.html