Copy link to clipboard
Copied
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?
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>
fi
Copy link to clipboard
Copied
<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
Copy link to clipboard
Copied
ListFirst will also work. Nice to have choices.
Copy link to clipboard
Copied
To augment Dan's reply. ![]()
http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_13.html
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more