fromLong

Returns a Decimal representing the specified value.

This function preserves the canonical representation of value.


Calling from Kotlin

Here's an example of calling this function from Kotlin code:

fun createsFromLong(input: Long, expected: String) {
val result: Decimal = Decimal.fromLong(input)
check("$result" == expected)
}

createsFromLong(input = 0, expected = "0")
createsFromLong(input = 42, expected = "42")
createsFromLong(input = -42, expected = "-42")
createsFromLong(
input = Long.MAX_VALUE,
expected = "9223372036854775807"
)
createsFromLong(
input = Long.MIN_VALUE,
expected = "-9223372036854775808"
)

Calling from Java

Here's an example of calling this function from Java code:

final BiConsumer<Long, String> createsFromLong = (input, expected) -> {
final Decimal result = Decimal.fromLong(input);
final boolean check = String.valueOf(result).equals(expected);
if (!check) throw new IllegalStateException("Check failed.");
};

createsFromLong.accept(0L, "0");
createsFromLong.accept(42L, "42");
createsFromLong.accept(-42L, "-42");
createsFromLong.accept(Long.MAX_VALUE, "9223372036854775807");
createsFromLong.accept(Long.MIN_VALUE, "-9223372036854775808");