Reputation: 15
I need to calculate 4.0468564224e-33
value. But unfortunately I am getting a result of 0.0000000
. I think the problem is at the e
value.
How can I calculate these mathematical calculation? Is there any necessity of importing mathematical classes?
Upvotes: 0
Views: 195
Reputation: 385744
Anders Lindahl explained why you see zero, but didn't suggest any solution.
One solution is to request the output of more decimals by using %.43f
instead of %f
(%.7f
).
Another solution is to request exponentiation notation by using %e
(%.10e
) instead of %f
.
Upvotes: 2
Reputation: 42870
4.0468564224e-33
is 4.0468564224 * 10⁻³³
, that is 0.0000000000000000000000000000000040468564224
- very close to zero.
If your output function is rounding to 7 decimal digits, you would get 0.0000000
as output even though the input is correct.
Upvotes: 2
Reputation: 31722
Try using NSNumber
for your large double
calculation.
Read Apple Doc for NSNumber
See SO post for NSNumber
NSNumber Calculations & precision?
Upvotes: 0
Reputation: 5879
Probably you are using something like
NSLog("%d", yourValue);
while you should use:
NSLog("%f", yourValue);
since your value is a float and not an integer.
%d => int
%f => float
Upvotes: 0