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?
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.