Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the math property of js

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to use the math attribute of js", the content is simple and clear, hoping to help you solve your doubts, let the editor lead you to study and learn "how to use the math attribute of js" this article.

/ / arithmetic object Math

/ / rounding up

Console.info (Math.ceil 26.1)

/ / rounding down

Console.info (Math.floor 26.1)

/ / rounding

Console.info (Math.round 26.1)

/ / absolute value

Console.info (Math.abs (- 26.1))

/ / get the random number 0-1 (not included)

Console.info (Math.random ())

/ / derivation: get a random integer between 0 and 9 multiplied by 10 and rounded down

Var randomnum = Math.floor (Math.random () * 10)

Console.info ("random integers (0-9)" + randomnum)

/ / derivation: get a four-digit random integer with a range of 1000-9999

/ / suppose you get the minimum random number 0 maximum number-minimum number + 1

Var num = Math.floor (Math.random () * (9999-1000001))

Console.info ("random four-digit integers (1000-9999)" + num)

/ / Math.random () * ((9999-1000001) + 1000)

/ / Math.floor (Math.random () * (9999-1000001))

The colors selected this time are:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report