On Jun 23, 1:51 pm, Selvam <kalaiselva...@gmail.comwrote:

I am getting exponent value when doing float arithmetic in

C++. Instead of that I need accurate value.

I'm not sure what you mean by "accurate value". You're

probablyl getting a reasonably accurate value in the results,

but just not formatting it correctly.

float amount = 0.0f;

float x = 0.99999976f;

amount= 1.0f - x;

I am getting amount as 2.3841858e-007 instead of 0.00000024

Which is probably more accurate. (Note that despite what you

wrote, you certainly never had a float value of 0.99999976.) Of

course, if what you want is the value rounded to 8 points after

the decimal, then you have to tell the computer to output it

like that:

std::cout.setf( std::ios::fixed, std::ios::floatfield ) ;

std::cout.precision( 8 ) ;

std::cout << x ;

Typically, of course, you'll wrap those first two statements in

some sort of application specific manipulator, and write

something like:

std::cout << appliFmt << x ;

(Also: float is only good for six or seven decimal digits

accuracy; you probably want to consider double.)

Can anyone tell what will be the solution for this problem???

Note : I am getting correct value in C#.Net but not in C++

I'm pretty sure that you're getting the same results in both

cases. But the default formatting isn't necessarily the same.

--

James Kanze (GABI Software) email:ja*********@gmail.com

Conseils en informatique orientée objet/

Beratung in objektorientierter Datenverarbeitung

9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34