The `toStringAsFixed` method in Dart returns a decimal-point string representation of this number with a specified number of fraction digits.
The syntax of int.toStringAsFixed() method is:
String toStringAsFixed(int fractionDigits)
This toStringAsFixed() method of int returns a decimal-point string-representation of this.
Parameter | Optional/Required | Description |
---|---|---|
fractionDigits | required | The number of digits after the decimal point. |
int.toStringAsFixed() returns value of type String
.
In this example,
num1
with the value 1000.toStringAsFixed(2)
method to get a fixed decimal representation with 2 fraction digits.void main() {
int num1 = 1000;
String result1 = num1.toStringAsFixed(2);
print('Fixed decimal representation of $num1: $result1');
}
Fixed decimal representation of 1000: 1000.00
In this example,
num2
with the value -25.toStringAsFixed(3)
method to get a fixed decimal representation with 3 fraction digits.void main() {
int num2 = -25;
String result2 = num2.toStringAsFixed(3);
print('Fixed decimal representation of $num2: $result2');
}
Fixed decimal representation of -25: -25.000
In this Dart tutorial, we learned about toStringAsFixed() method of int: the syntax and few working examples with output and detailed explanation for each example.