Transforms a number into a string with specified precision
format-number
@/format-number
Transforms a number into a string with specified precision
#pragma XOD dirtieness disable
node {
char str[16];
CStringView view = CStringView(str);
void evaluate(Context ctx) {
auto num = getValue<input_NUM>(ctx);
auto dig = getValue<input_DIG>(ctx);
formatNumber(num, dig, str);
emitValue<output_STR>(ctx, XString(&view));
}
}
| NUM | DIG | STR |
|---|
| 0 | 4 | "0.0000" |
| 1 | 2 | "1.00" |
| 1.3272 | 4 | "1.3272" |
| 1.3272 | 2 | "1.33" |
| 1.3272 | 0 | "1" |
| 1.4723 | 0 | "1" |
| 1.5 | 0 | "2" |
| 1.5 | -2 | "2" |
| -1.1992 | 4 | "-1.1992" |
| -1.449 | 2 | "-1.45" |
| -1.59 | 0 | "-2" |
| -1.59 | -2 | "-2" |
| -1.59 | -2 | "-2" |
| .257 | 2 | "0.26" |
| .257 | 1 | "0.3" |
| .257 | 0 | "0" |
| -.257 | 2 | "-0.26" |
| -.257 | 1 | "-0.3" |
| -.257 | 0 | "0" |
| -.657 | 0 | "-1" |
| 123.456 | -2 | "123" |
| -0.256 | -7 | "0" |
| 99000000000 | 0 | "OVF" |
| 99000000000 | 2 | "OVF" |
| -99000000000 | 0 | "-OVF" |
| -99000000000 | 2 | "-OVF" |
| NaN | 0 | "NaN" |
| Inf | 0 | "Inf" |
| -Inf | 0 | "-Inf" |
| NaN | 2 | "NaN" |
| Inf | 2 | "Inf" |
| -Inf | 2 | "-Inf" |