Every line of 'javascript format float' 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.
16 export function floatFormat(n) { 17 const pows = { 18 1: { text: 'B', pow: 0 }, 19 2: { text: 'B', pow: 0 }, 20 3: { text: 'B', pow: 0 }, 21 4: { text: 'Kb', pow: 3 }, 22 5: { text: 'Kb', pow: 3 }, 23 6: { text: 'Kb', pow: 3 }, 24 7: { text: 'Mb', pow: 6 }, 25 8: { text: 'Mb', pow: 6 }, 26 9: { text: 'Mb', pow: 6 }, 27 10: { text: 'Gb', pow: 9 }, 28 11: { text: 'Gb', pow: 9 }, 29 } 30 31 const len = String(n).length 32 const fmt = (n / Number(`1e${pows[len].pow}`)).toFixed(2) 33 const str = `${fmt} ${pows[len].text}` 34 35 return str 36 }
24 export function floatToString(float) { 25 return float.toFixed(2).replace(/[0\.]+$/, ''); 26 }
9 function float_precision(float_value, precision) { 10 float_value = parseFloat(float_value); 11 if (isNaN(float_value)) { 12 return parseFloat('0').toFixed(precision); 13 } 14 else { 15 var power = Math.pow(10, precision); 16 float_value = (Math.round(float_value * power) / power).toFixed(precision); 17 return float_value.toString(); 18 } 19 }
18 function Float (value) { 19 return Number(value) 20 }
115 function 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 }
17 public format(value: number): string { 18 return value.toFixed(this.digits_); 19 }