views:

75

answers:

2

Possible Duplicate:
Prevent scientific notation in ostream when using << with double

I get 1e-1 as result after a computation how can I convert the result from exponent to dot notation i.e., 0.1 ? Why is it automatically converted to exponential notation!!

+5  A: 

You can use the fixed I/O manipulator to force the number to be printed in fixed-point notation:

double d = 42.0;
std::cout << std::fixed << d;

(std::scientific does the opposite: it forces the number to be printed in scientific notation)

James McNellis
I would like to save the value in double!
yesraaj
@yesraaj: What do you mean? 42.0 is 42.0 and how you format it for printing has no effect on the stored value.
James McNellis
@James McNellis I save the value into a database, where I use double being converted to appropriate NUMBER type in Oracle.
yesraaj
@yesraaj: Then it's oracle that has the problem, not C++
DeadMG
A: 

Oracle (generally) doesn't do binary numbers (some support was added in 10g). Numbers are held in an internal format and, unless you use an implicit or explicit TO_CHAR, it is up to the "client" to display them (or any desired "prettifying").

select to_number('1e-1') num, 
       to_char(to_number('1e-1'),'9.9EEEE') sci_num, 
       to_char(to_number('1e-1')) std_num 
from dual;

            NUM SCI_NUM   ST
--------------- --------- --
            .10   1.0E-01 .1
Gary