Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   When I convert unsigned char to double, I'm losing the numbers after the decimal. (http://www.go4expert.com/forums/i-convert-unsigned-char-double-im-t5081/)

TheKidd88 4Jul2007 01:30

When I convert unsigned char to double, I'm losing the numbers after the decimal.
 
For example this simple program outputs 0 and not 0.9:

Code:

#include <iostream>
#include <string>
#include <fstream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main()
{
  unsigned char x = (unsigned char)0.9;
  double y = (double) x;
  cout << y << endl;
  return 0;
}

How can I fix this?

DaWei 4Jul2007 02:09

Re: When I convert unsigned char to double, I'm losing the numbers after the decimal.
 
An unsigned char is an integer. It has no fractional part.

Please, once again, read the "Before you make a query" thread and learn to use code tags. These are HTML pages, which means they eat whitespace. Use the tags to preserve your formatting and indentation. It's the polite thing to do in return for the free help.


All times are GMT +5.5. The time now is 02:51.