6 examples of 'javascript string to decimal' in JavaScript

Every line of 'javascript string to decimal' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
26export function fromDecimal(data, delim="Auto") {
27 delim = Utils.charRep(delim);
28 const output = [];
29 let byteStr = data.split(delim);
30 if (byteStr[byteStr.length-1] === "")
31 byteStr = byteStr.slice(0, byteStr.length-1);
32
33 for (let i = 0; i < byteStr.length; i++) {
34 output[i] = parseInt(byteStr[i], 10);
35 }
36 return output;
37}
81static parse(value) {
82 return value;
83}
311function convertDecimal(value, surroundDecimalsWith) {
312 if (/^-?([0]|([1-9][0-9]*))(\.[0-9]+)?$/.test(value) == false) {
313 throw new Error("value supposed to be a decimal number but got: " + value);
314 }
315 if (surroundDecimalsWith) {
316 return {
317 value: value,
318 toJSON: function () {
319 return surroundDecimalsWith.str + value + surroundDecimalsWith.str;
320 }
321 };
322 }
323 else {
324 return value;
325 }
326}
92function toDecimal(val, decimalPlaces = 2) {
93 const x = Math.pow(10, decimalPlaces);
94 return parseFloat(Math.round(Number(val) * x) / x).toFixed(decimalPlaces);
95}
115function formatDecimal(valueAsNumber) {
116 if (!hasDecimalPlaces(valueAsNumber)) {
117 return Math.round(valueAsNumber).toString();
118 }
119 let text = valueAsNumber.toFixed(1);
120 return text.endsWith('.0') ? Math.round(valueAsNumber).toString() : text;
121}
1040toBigDecimal(): BigDecimal {
1041 assert(this.kind == ValueKind.BIGDECIMAL, 'Value is not a BigDecimal.')
1042 return changetype(this.data as u32)
1043}

Related snippets