subaruwrx88011 wrote:
Is there anyway to convert a float to an unsigned int without loss of
precision?
Here is what I have....
float giga_hertz;
unisigned int hertz;
giga_hertz = 4.2;
hertz = (unsigned int) (1000000000 * giga_hertz);
I can't get hertz to equal 4,200,000,000.
I presume your unsigned int is, or more than, 32 bits. If that's so,
do
hertz = (unsigned int) (1000000000.5 * giga_hertz);
If that's not so, you will never get 4,200,000,000. You need 32 bits.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask