Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Math.fround( ) Function

Improve Article
Save Article
  • Last Updated : 30 Dec, 2022
Improve Article
Save Article

The Javascript Math.fround() function is used to return the nearest 32-bit single-precision float representation of a number. The Math.fround() function in JavaScript is also used to cast the 64-bit float to a 32-bit float. 

Syntax:

Math.fround(value)

Parameters: This function accepts a single parameter value. This parameter represents the number for which we want to find the nearest 32-bit single-precision float representation. 

Return Value: The Math.fround() function returns the nearest 32-bit single-precision float representation of the given number. 

Below examples illustrates the Math.fround() function in JavaScript:

Example 1: When a positive number is passed as a parameter: 

Javascript




<script type="text/javascript">
    console.log(Math.fround(3));        
</script>

Output:

3

Example 2: When a positive number with decimal places is passed as a parameter: 

Javascript




<script type="text/javascript">
    console.log(Math.fround(3.345));        
</script>

Output:

3.3450000286102295

Example 3: When a negative number is passed as a parameter: 

Javascript




<script type="text/javascript">
    console.log(Math.fround(-3));        
</script>

Output:

-3

Example 4: When a negative number with decimal places is passed as a parameter: 

Javascript




<script type="text/javascript"
    console.log(Math.fround(-3.345));        
</script>

Output:

-3.3450000286102295

Example 5: When zero is passed as a parameter: 

Javascript




<script type="text/javascript">
    console.log(Math.fround(0));        
</script>

Output:

0

We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.

Supported Browsers: The browsers supported by JavaScript Math.fround( ) function are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!