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

Need help getting the digits without the decimal

Explorer ,
Apr 14, 2010 Apr 14, 2010

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?

TOPICS
Getting started
662
Translate
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

Community Expert , Apr 15, 2010 Apr 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>
fi

...
Translate
Valorous Hero ,
Apr 14, 2010 Apr 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

Translate
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
LEGEND ,
Apr 14, 2010 Apr 14, 2010

ListFirst will also work.  Nice to have choices.

Translate
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
Valorous Hero ,
Apr 14, 2010 Apr 14, 2010

To augment Dan's reply. 

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

Translate
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
Community Expert ,
Apr 15, 2010 Apr 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>

Translate
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
LEGEND ,
Apr 15, 2010 Apr 15, 2010
LATEST

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

Translate
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