How can i get accurate resultsof mathematical calculations in objective-c? -
i have simple mathematical calculation. have 2 floats n1 , n2.when evaluate simple division on these floats cannot accurate result in calculator. here simple code
float n1=55; float n2=23; float n=n1/n2; nslog(@"%.15f",n);
i see on console . wanted precesion upto 15 digits after decimal hence .15f
2.391304254531860
but when calculate same division of 2 floats in scientific calculator value follows. how can same value using code?
2.391304347826087
am missing silly , obvious? of great use. tia
the double
type should used instead of float
if need higher accuracy in calculations. double
uses more bits store values float
.
Comments
Post a Comment