vue中math.ceil
“The universe is regulated by Math formulas” my grumpy teacher used to say. And the galaxy of coding isn’t escaping from that rule any time soon — as I was hoping. Luckily for us, a language like JavaScript gives us tools like the Math object to deal with numbers and their operations.
我的脾气暴躁的老师曾经说过:“ 宇宙受数学公式的约束 。” 正如我希望的那样,编码的银河系不会很快逃脱该规则。 对我们来说幸运的是,像JavaScript这样的语言为我们提供了诸如Math对象之类的工具来处理数字及其运算。
When it comes to rounding numbers, Math helps you with three main functions: Math.ceil
, Math.floor
and Math.round
.
舍入数字时, Math可通过三个主要功能帮助您: Math.ceil
, Math.floor
和Math.round
。
数学细胞 (Math.ceil)
This method rounds up the only passed in value to the nearest greater integer. I find the word ceil meaningful in this case, as it reminds to a ceiling, to bringing something up. Or in our case, to raise a number to the next one.
此方法将唯一传入的值四舍五入为最接近的较大整数 。 在这种情况下,我想起ceil这个词很有意义,因为它想起了一个上限,可以提出一些东西。 或者在我们的情况下,将数字提高到下一个。
![Using Math.ceil](https://miro.medium.com/max/9999/1*b5zhnKbXlT7kUut8rfuxQg.png)
数学地板 (Math.floor)
The word used in this context can help you imagine what this method does. Bringing something down, to the floor, lowering the only provided number to its nearest integer.
在此上下文中使用的单词可以帮助您想象此方法的作用。 将某些东西放到地板上,将唯一提供的数字降低到最接近的整数。
![Using Math.floor](https://miro.medium.com/max/9999/1*1AsJhMcggqpLVNM9lqQZJw.png)
数学圆 (Math.round)
This method will resemble what you probably learned in school if you were paying more attention than me: the final rounded value depends on the fractional part. So if you have that to be ≥ 5, the provided number will be rounded up, down otherwise.
如果您比我更关注,此方法将类似于您在学校可能学到的方法:最终四舍五入的值取决于小数部分。 因此,如果您的数字等于或大于5,则所提供的数字将四舍五入,否则将四舍五入。
![Using Math.round](https://i-blog.csdnimg.cn/blog_migrate/4149063a583372ce7daac7712912364c.png)
结论 (Conclusion)
As always, thanks for spending time reading the article. Don’t forget to provide feedback and opinions in the comments section.
与往常一样,感谢您花时间阅读本文。 不要忘记在评论部分中提供反馈和意见。
— Piero
— 皮耶罗
资源资源 (Resources)
普通英语JavaScript (JavaScript In Plain English)
Enjoyed this article? If so, get more similar content by subscribing to Decoded, our YouTube channel!
喜欢这篇文章吗? 如果是这样,请订阅我们的YouTube频道解码,以获得更多类似的内容!
vue中math.ceil