Constructors

There are multiple ways you can create a Fixed object

  • Fixed.fromInt

  • Fixed.fromBigInt

  • Fixed.fromDecimal

  • Fixed.parse

  • Fixed.fromNum

Example 1

import 'package:decimal/decimal.dart';
import 'package:fixed/fixed.dart';

Fixed.fromInt(1234, scale: 3); // == 1.234

Fixed.fromBigInt(BigInt.from(1234), scale: 3); // == 1.234

final t1 = Fixed.fromDecimal(Decimal.fromInt(1), scale: 2); // == 1.00

final t3 = Fixed.parse('1.234'); // == 1.234, scale: 3

final t3 = Fixed.parse('1.234', scale: 2); // == 1.23, scale: 2

// This is the least desireable method as it can introduce
// rounding errors.
final t2 = Fixed.fromNum(1.234, scale: 3); // == 1.234

Last updated