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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert from a variable in double to long??

Status
Not open for further replies.

rhpingwoo

Programmer
Mar 5, 2003
15
AU
Hi,

I am trying to convert a variable from double to long.
Anybody have any idea of how to do this without losing any of the number after the decimal point??

I have try to first convert it to a string using _fcvt(),
and then from string convert it back to long using atol().

But it doesn't work, anybody have any ideas???

Regards,
Raphael
 
>> how to do this without losing any of the number after
>> the decimal point??

LOL That's a good one! But this is not the "humor" forum.

You must not be stating your question correctly.

223.105

"223" before the decimal
"105" after the decimal

type "long" is a "whole number" not a "real number"
So you can't keep the digits after the decimal.

-pete

 
Sometimes there is sence to process real numbers using int variable type. You must decide, what number of positions after the decimal point you want to have and process numbers multiplyed by 10^n, remembering, that the real position of the decimal point is before the n-th digit from the right. It is usefull, when you need speed or want to avoid errors, which are always present in float calculations.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top