Search code examples
cscientific-notation

convert numbers in scientific notation to decimal


Write a C program to convert a number in scientific notation to its equivalent decimal form :
Given
8.3e+2 output = 830
2.E-1 output = 0.2
4.3E2 output = 430
Is there any inbuilt library or function in C/C++ which can do this?
or one will have to write his own code, in that case, any easy way to achieve this?


Solution

  • try this

    #include <iostream>
    #include <string>
    
    
    int32_t main(int32_t argc, char *argv[]) {
        std::string str = "8.3e+2";
        std::cout << std::stod(str) << std::endl;
        
        return EXIT_SUCCESS;
    }