使Java代码中的大量数字更具可读性 [英] Making large numbers in Javascript code more readable

查看:61
本文介绍了使Java代码中的大量数字更具可读性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使大量数字(即1000000)在JS代码中更具可读性?

Is there a way to make a large number, i.e. 1000000, more readable in JS code?

我知道在Ruby中您可以改写1_000_000,这使得在视觉上进行识别变得容易得多.

I know in Ruby you can write 1_000_000 instead, which makes it a lot easier to identify visually.

谢谢.

推荐答案

在这种情况下,我通常使用乘法;在这种情况下,我将使用 1000 * 1000 .其他例子

I generally use multiplication in this situation; in this case I'd use 1000 * 1000. Other examples

one megabytes is 1000 * 1024
one hour (in milliseconds) is 60 * 60 * 1000

等这与下划线表示法不太一样,但是另一方面,它不需要特殊的语言支持.

etc. This isn't quite as nice as the underscore notation, but on the other hand, it requires no special language support.

另一种方法是定义常量",例如:

Another approach is to define "constants", for example:

var ONE_MILLION = 1000000;

或将两者结合在一起:

var ONE_MILLION = 1000 * 1000;

这篇关于使Java代码中的大量数字更具可读性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆