最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use scientific notation in js? - Stack Overflow

programmeradmin6浏览0评论
var a = 5.0;
var b = a * 10e-12;
b *= 10e+12
print(b)

Why b equals 500 instead of 5?

As far as I know 10^(-12) equals to 1/(10^12), how can i rewrite the code?

var a = 5.0;
var b = a * 10e-12;
b *= 10e+12
print(b)

Why b equals 500 instead of 5?

As far as I know 10^(-12) equals to 1/(10^12), how can i rewrite the code?

Share Improve this question edited Nov 26, 2014 at 14:21 zzzzBov 179k56 gold badges327 silver badges371 bronze badges asked Nov 26, 2014 at 14:12 user983302user983302 1,4373 gold badges15 silver badges23 bronze badges 2
  • 2 actually. 10e12 is 1e13 – Marc B Commented Nov 26, 2014 at 14:17
  • So stupid mistake, thank you all for clarification. – user983302 Commented Nov 26, 2014 at 14:24
Add a comment  | 

2 Answers 2

Reset to default 15

10-12 × 1012 = 1

But what you wrote wasn't 10-12, nor did you write 1012.

What you wrote was 10 × 1012 and 10 × 10-12:

10 × 1012 × 10 × 10-12 = 100

100 × 5 = 500

Proper scientific notation is 1e-12 and 1e12. The e stands for "ten to the power of", so you don't need to multiply that value by ten again.

"As far as I know 10^(-12) equals to 1/(10^12)" -- that is correct, but 10e-12 actually means 10*10^(-12)

发布评论

评论列表(0)

  1. 暂无评论