Files
languageservices/expressions/src/data/number.ts
T

24 lines
640 B
TypeScript
Raw Normal View History

import {ExpressionDataInterface, Kind} from "./expressiondata.js";
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) {
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;
}
}