Values getting Overflowed while converting Bit into TB

44 Views Asked by At

I am making a calculator for converting bits, bytes, MB, KB, GB, TB, EB, PB into each other. Right now I am converting my bit value (1,000,000) into TB using a long double data type because float is giving 0.0000 as definitely the result is out the range. But while I am using long double, its giving me its smallest possible value -2.863e+36, instead of giving me the actual result: 0.0001220703125 which should fall in range.

#include <stdio.h>

void main() {
    double valueInBits = 1000000.0; // 1 million bits (use double for floating-point precision)

    // converting valueInBits into TB
    valueInBits = valueInBits / 8.0;
    valueInBits = valueInBits / 1024.0;
    valueInBits = valueInBits / 1024.0;
    valueInBits = valueInBits / 1024.0;
    valueInBits = valueInBits / 1024.0;

    printf("%f TB", valueInBits);
}
0

There are 0 best solutions below