How to round double numbers with limit the numbers with decimal places in Dart/ Flutter By Examples

This tutorial shows you how to round double numbers with a limit to precision.

For example, if the double number is 12.12345, limit the number of decimal places from 3 to 12.123. Let’s see an example.

Double-precision after decimal places in dart

There are two ways we can convert double to limit decimal places to n times. One way, use the double toStringAsFixed method. The toStringAsFixed method takes fractionDigits and returns the string representation of double numbers with decimal digits limit fractionDigits. Syntax:

String toStringAsFixed(int fractionDigits)

Returns String version double value.

Convert string into double using double.parse() method.

Another way, use the double toStringAsExponential method.

The toStringAsExponential method takes fractionDigits and returns a string version of a double value with limited decimal places. Syntax:

String toStringAsExponential([int? fractionDigits])

Return String, which can be converted to double.parse() method

Here is an example

void main() {
  double d = 12.12349;
  String result = d.toStringAsFixed(4);
  var result1 = double.parse(d.toStringAsExponential(3));




To summarize, Limit the double floating decimal precision with examples.

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.