conversion from 'double' to 'unsigned int',
-
Hi i want to know how can i convert a "double value" to "unsigned int" without possible loss of data. unsigned int numr; double num1; numr= fread (buff,sizeof(char),num1,pFile); alok singh chauhan
-
Hi i want to know how can i convert a "double value" to "unsigned int" without possible loss of data. unsigned int numr; double num1; numr= fread (buff,sizeof(char),num1,pFile); alok singh chauhan
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_data_conversion.asp[^] maybe it is some helpful to you
-
Hi i want to know how can i convert a "double value" to "unsigned int" without possible loss of data. unsigned int numr; double num1; numr= fread (buff,sizeof(char),num1,pFile); alok singh chauhan
It's impossible. For example, 1.5 can't be converted an integer without loss of data. 1 or 2 are the two closest but we lose .5 either way. I'm not sure what the code you quoted is trying to do?..... Steve
-
Hi i want to know how can i convert a "double value" to "unsigned int" without possible loss of data. unsigned int numr; double num1; numr= fread (buff,sizeof(char),num1,pFile); alok singh chauhan
Are you serious? 1. A double might contain more bits than an unsigned integer. Hence conversion loss. 2. A double can have decimal places, which an unsigned integer lacks. Hence conversion loss. -- The Blog: Bits and Pieces
-
Hi i want to know how can i convert a "double value" to "unsigned int" without possible loss of data. unsigned int numr; double num1; numr= fread (buff,sizeof(char),num1,pFile); alok singh chauhan
-
Hi i want to know how can i convert a "double value" to "unsigned int" without possible loss of data. unsigned int numr; double num1; numr= fread (buff,sizeof(char),num1,pFile); alok singh chauhan
The answer, quite simply, is that you can not in general convert from double (or float) to unsigned int with no data loss! Because double is a floating point format, it might contain a fractional part, which will be discarded in any conversion. And a double might be very large or very small (because it allows powers of 10.) If the double represents an integer in the range supported by an unsigned int, then no conversion is necessary - it can be stored. Lastly, if the double represents something like degrees, with resolution of 0.01 degree and range of 0 to 359.99 degree, you could scale the value - multiply the double by 100.0, add 0.1, then store it in the unsigned int with no data loss.
-
Hi i want to know how can i convert a "double value" to "unsigned int" without possible loss of data. unsigned int numr; double num1; numr= fread (buff,sizeof(char),num1,pFile); alok singh chauhan
Well, a 'double' is 8 bytes length and a 'int' is 4 bytes length. So, i think, it's impossible to do that. What's with your example?