2025-12-18 13:35:48 -06:00
|
|
|
import {ExpressionDataInterface, Kind} from "./expressiondata.js";
|
2023-01-06 15:54:31 -08:00
|
|
|
|
|
|
|
|
export class NumberData implements ExpressionDataInterface {
|
|
|
|
|
constructor(public readonly value: number) {}
|
|
|
|
|
|
|
|
|
|
public readonly kind = Kind.Number;
|
|
|
|
|
|
|
|
|
|
public primitive = true;
|
|
|
|
|
|
|
|
|
|
coerceString(): string {
|
2023-03-16 12:30:15 -04:00
|
|
|
if (this.value === 0) {
|
2023-01-06 15:54:31 -08:00
|
|
|
return "0";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Workaround to limit the precision to at most 15 digits. Format the number to a string, then parse
|
|
|
|
|
// it back to a number to remove trailing zeroes to prevent numbers to be converted to 1.200000000...
|
|
|
|
|
return (+this.value.toFixed(15)).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
number(): number {
|
|
|
|
|
return this.value;
|
|
|
|
|
}
|
|
|
|
|
}
|