target string
Decimal if succceeded.
import std.exception : assertThrown; import std.range : array, repeat; assert(Decimal.fromString(".123456") == Decimal(123456, 6)); assert(Decimal.fromString("123.456") == Decimal(123456, 3)); assert(Decimal.fromString("12345.6") == Decimal(123456, 1)); assert(Decimal.fromString("123456.") == Decimal(123456, 0)); assert(Decimal.fromString("123456") == Decimal(123456, 0)); assert(Decimal.fromString("0.001") == Decimal(1, 3)); assert(Decimal.fromString("100.000") == Decimal(100000, 3)); assert(Decimal.fromString("a123456").isNull); assert(Decimal.fromString("123.456a").isNull); string zeros = '0'.repeat(ubyte.max - 1).array; assert(Decimal.fromString("." ~ zeros ~ "1") == Decimal(1, ubyte.max)); assert(Decimal.fromString("." ~ zeros ~ "01").isNull); assert(Decimal.fromString("+123.456") == Decimal(+123456, 3)); assert(Decimal.fromString("-123.456") == Decimal(-123456, 3)); assert(Decimal.fromString("+.123456") == Decimal(123456, 6)); assert(Decimal.fromString("-.123456") == Decimal(-123456, 6));
Parse price number from string.