开发者

how to calculate mathematical double values

开发者 https://www.devze.com 2023-02-28 01:34 出处:网络
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.

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?


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.


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.


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


Try using NSNumber for your large double calculation. Read Apple Doc for NSNumber

See SO post for NSNumber

NSNumber Calculations & precision?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号