toFixed

Summary

Formats the integer value using fixed-point notation.

Usage

public string toFixed(int digits)

Returns

The integer value formatted using fixed-point notation.

Parameters

digits

The number of digits to appear in the final formatted value after the decimal point. This number can be between 0 and 20 (inclusive).

Description

Formats the integer value using fixed-point notation.

The formatted value will be returned as a string.

The argument expects a number that specifies how many digits should appear after the decimal point in the formatted string.

System.Exceptions.OutOfRangeException will be thrown if the supplied argument is not an integer between 0 and 20 (inclusive).

For integer values, toFixed will always pad with zeroes beyond the decimal point. Thus, the final formatted string for toFixed(1) will be "x.0", "x.00" for toFixed(2), "x.000" for toFixed(3), and so forth (where x is the original integer value).

Examples

Basic Usage
1
2
3
4
5
import System;
 
unsigned int x = 1;
Console.log(x.toFixed(5)); // "1.00000"
Console.log(x.toFixed(7)); // "1.0000000"

Share

HTML | BBCode | Direct Link