Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get only figures after a decimal point

Status
Not open for further replies.

namax

Technical User
May 22, 2011
19
PG
Is there a function in visual foxpro that can be used to get the figures after a decimal point in a numerical field.

INT() function obviously is for picking up numbers before a decimal point in a numerical field for example 389.9938.If INT() is used, 389 will be shown but how about the numbers after the decimal point.What function would be use to get the remaining figures ie 9938.

Could anyone help in this.

Thankyou in advance
 

mval = 389.9938

?INT(val(SUBSTR(TRANSFORM(mval),AT('.',TRANSFORM(mval),1)+1)))


 
You already got the answer in the other thread, it's simply using the Int() function again, subtracting the int part:

cents = currency - Int(currency)

Bye, Olaf.
 
You can also use

MOD(389.9938, 1)

to return .9938, but I'd use subtracting the INT() like Olaf shows above because its easier to read the code when looking at it in the future
 
Well, depends on your interpretation.

value = -1.2300
dollars = Int(value)
cents = value - Int(value)

yields dollars: -1, cents: -.23

I'd not say this is incorrect. In a negative currency value both dollars and cents are negative, the sum is the correct full value. For printing this isn't optimal, but the math is fully correct.

For printing/output you should rather use TRANSFORM anyway, and the settings SET CURRENCY RIGHT/LEFT plus SET CURRENCY TO '$' or whatever other currency symbol.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top