
Number To String X Decimals
Downloads: 14
Download Description
Converts a Number to a String while keeping the desired (X) decimal places
//
// NumberToStringXDecimals.ts
// Converts a Number to a String while keeping the desired (X) decimal places
// Written by @Fusedthreed – https://FusedThreeD.com
//
@customNode()
export class NumberToStringXDecimals extends BasicScriptNode {
@input()
number: number;
@input()
Decimals: number = 2;
@output()
string: string;
@output()
ConvertedNumber: number;
execute() {
// Round normally
let factor = Math.pow(10, this.Decimals);
let rounded = Math.round(this.number * factor) / factor;
// Keep trailing zeros in the string output
this.string = rounded.toFixed(this.Decimals);
// Keep the numeric output as a number
this.ConvertedNumber = rounded;
}
}