5 examples of 'parse decimal javascript' in JavaScript

Every line of 'parse decimal javascript' 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
this disclaimer
81static parse(value) {
82 return value;
83}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

7export default function formatDecimal (value: string): string {
8 // We can do this by adjusting the regx, however for the sake of clarity
9 // we rather strip and re-add the negative sign in the output
10 const isNegative = value[0].startsWith('-');
11 const matched = isNegative
12 ? value.substr(1).match(NUMBER_REGEX)
13 : value.match(NUMBER_REGEX);
14
15 return matched
16 ? `${isNegative ? '-' : ''}${matched.join(',')}`
17 : value;
18}
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}
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}
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}

Related snippets