JavaScript: Math fround() function
This JavaScript tutorial explains how to use the math function called fround() with syntax and examples.
Description
In JavaScript, fround() is a function that is used to round a number to a 32-bit single precision float value. Because the fround() function is a static function of the Math object, it must be invoked through the placeholder object called Math.
Syntax
In JavaScript, the syntax for the fround() function is:
Math.fround(number);
Parameters or Arguments
- number
- The number which will be rounded to a 32-bit single precision float number.
Returns
The fround() function returns the number rounded to a 32-bit single precision float value.
Note
- Math is a placeholder object that contains mathematical functions and constants of which fround() is one of these functions.
Example
Let's take a look at an example of how to use the fround() function in JavaScript.
For example:
console.log(Math.fround(32));
console.log(Math.fround(8.1));
console.log(Math.fround(-4.2));
In this example, we have invoked the fround() function using the Math class.
We have written the output of the fround() function to the web browser console log, for demonstration purposes, to show what the fround() function returns.
The following will be output to the web browser console log:
32 8.100000381469727 -4.199999809265137
In this example, the first output to the console log returned 32 which is the rounded 32-bit single precision float representation of 32.
The second output to the console log returned 8.100000381469727 which is the rounded 32-bit single precision float representation of 8.1.
The third output to the console log returned -4.199999809265137 which is the rounded 32-bit single precision float representation of -4.2.
Advertisements