Archive Pages Design$type=blogging

How to use Round, Random, Min and Max in JavaSript

Round, Random, Min and Max are the methods used in math object in JavaSript. Math object allows you to perform common mathematical tasks. Th...

Round, Random, Min and Max are the methods used in math object in JavaSript. Math object allows you to perform common mathematical tasks. The math object includes several mathematical values and functions. Yo do not need to define the math object before using it. In this post I am describing How to use Round, Random, Min and Max in JavaSript.

How to use Round() in JavaScript


Using round() method in math object, you can round the given numbers as given below.

<script>
document.write(Math.round(0.60) +"<br/>");
document.write(Math.round(0.40) +"<br/>");
document.write(Math.round(0.49) +"<br/>");
document.write(Math.round(-3.69) +"<br/>");
document.write(Math.round(-6.10) +"<br/>");
</script>

Preview:


How to use Random() in JavaScript


You can use the random() method in math object,you can return a random number between 0 and 1 as given below.

<script>
document.write(Math.random());
</script>

Preview:


How to use Max() in JavaScript


Using max() method in math object, you can return the number with the highest value of two specified numbers as the following.

<script>
document.write(Math.max(9,3) +"<br/>");
document.write(Math.max(-5,7) +"<br/>");
document.write(Math.max(10,21) +"<br/>");
document.write(Math.max(-5,-9) +"<br/>");
document.write(Math.max(6.12,7.98) +"<br/>");
</script>

Preview:



How to use Min() in JavaScript


Using min() method in math object, you can return the number with the highest value of two specified numbers as the following.

<script>
document.write(Math.min(9,3) +"<br/>");
document.write(Math.min(-5,7) +"<br/>");
document.write(Math.min(10,21) +"<br/>");
document.write(Math.min(-5,-9) +"<br/>");
document.write(Math.min(6.12,7.98) +"<br/>");
</script>

Preview:


There are also other more methods on JavaScript math object to perform common mathematical tasks which are listed below along with their description. You can use them as the methods given above.
  • abs(x):  Returns the absolute value of a number
  • ceil(x): Returns the value of a number rounded upwards to the nearest integer
  • exp(x):  Returns the value or E^x.
  • floor(x): Returns the value of a number rounded downwards to the nearest integer.
  • log(x):  Returns the natural logarithm (base E) of a number.
  • pow(x,y): Returns the value of x to the power of y.
  • sqrt(x):  Returns the square root of a number.



Related Search Terms

تعليقات

الاسم

Artificial Intelligence(AI) Backlinking Basic IT Best List Blogging Tips C C# C++ Computer Architecture Computer Fundamental Computer Security Computer/IT Officer Exam CSS Data Mining and Warehousing Data Recovery Tools Data Structure Database Management System E-commerce E-government Internet & Web Designing IT Law IT Tips and Tricks IT Tutorials Java JavaScript Keyword Research Tools MIS Multiple Choice Question (MCQ) Networking Online Earning Online IT Jobs Operating System Oracle Forms and Reports Programming Guide Programming Language SEO Social Networking Sites Software Download Software Engineering System Analysis and Design Top List VB.Net
false
rtl
item
Max5: How to use Round, Random, Min and Max in JavaSript
How to use Round, Random, Min and Max in JavaSript
Max5
https://maxs27.blogspot.com/2015/02/how-to-use-round-random-min-and-max-in.html
https://maxs27.blogspot.com/
http://maxs27.blogspot.com/
http://maxs27.blogspot.com/2015/02/how-to-use-round-random-min-and-max-in.html
true
1760660989564394152
UTF-8
لم يتم العثور على اى مواضيع شاهد الكل اقرأ المزيد رد احذف الرد حذف بواسطة الرئيسية صفحات مواضيع شاهد الكل نوصى لك التسميات الارشيف بحث لم يتم العثور على ماتبحث عنه عودة للرئيسية الاحد الاثنين الثلاثاء الاربعاء الخميس الجمعة السبت الاحد الاثنين الثلاثاء الاربعاء الخميس الجمعة السبت يناير فبراير مارس ابريل مايو يونيو يوليو اغسطس سبتمبر اكتوبر نوفمبر ديسمبر يناير فبراير مارس ابريل مايو يونيو يوليو اغسطس سبتمبر اكتوبر نوفمبر ديسمبر just now 1 دقيقة مضت $$1$$ دقيقة مضت 1 hour ago $$1$$ ساعة مضت الامس $$1$$ يوم مضى $$1$$ اسبوع مضى اكثر من 5 اسابيع مضت