doubleToBigEndian method
Converts a numeric value (either integer or double) to a 64-bit big-endian integer.
This method takes a numeric amount
and converts it to a 64-bit integer in big-endian format.
If the amount
is an integer, it is multiplied by 10^8 (8 decimal places are added).
If the amount
is a double, it is converted to a string, split into integer and decimal parts,
and padded with zeros to ensure 8 decimal places. The resulting string is then parsed into
a 64-bit integer.
Parameters:
amount
The numeric value (integer or double) to be converted.
Returns:
- A 64-bit integer in big-endian format representing the converted value.
Note: If the input is not a valid numeric type (int or double), the method returns 0.
Implementation
int doubleToBigEndian(dynamic amount) {
if (amount is int) {
return int.parse("${amount}00000000");
}
if (amount is double) {
List<String> tempArray = amount.toString().split('.');
while (tempArray[1].length < 8) {
tempArray[1] += '0';
}
return int.parse(tempArray[0] + tempArray[1]);
}
return 0;
}