Is there any JavaScript standard API to parse to number according to locale?

The NPM package d2l-intl provides a locale-sensitive parser. It has since been superseded by @brightspace-ui/intl (essentially version 3), so some info below might or might not apply in its newer incantation. const { NumberFormat, NumberParse } = require(‘d2l-intl’); const formatter = new NumberFormat(‘es’); const parser = new NumberParse(‘es’); const number = 1234.5; console.log(formatter.format(number)); // 1.234,5 … Read more

Convert long number into abbreviated string in JavaScript, with a special shortness requirement

Approach 1: Built-in library I would recommend using Javascript’s built-in library method Intl.NumberFormat Intl.NumberFormat(‘en-US’, { notation: “compact”, maximumFractionDigits: 1 }).format(2500); Approach 2: No library But you can also create these abbreviations with simple if statements, and without the complexity of Math, maps, regex, for-loops, etc. Formatting Cash value with K const formatCash = n => … Read more

Formatting Large Numbers with .NET

You can use Log10 to determine the correct break. Something like this could work: double number = 4316000; int mag = (int)(Math.Floor(Math.Log10(number))/3); // Truncates to 6, divides to 2 double divisor = Math.Pow(10, mag*3); double shortNumber = number / divisor; string suffix; switch(mag) { case 0: suffix = string.Empty; break; case 1: suffix = “k”; … Read more

Convert number into xx.xx million format? [closed]

Try this from, https://php.net/manual/en/function.number-format.php#89888: <?php function nice_number($n) { // first strip any formatting; $n = (0+str_replace(“,”, “”, $n)); // is this a number? if (!is_numeric($n)) return false; // now filter it; if ($n > 1000000000000) return round(($n/1000000000000), 2).’ trillion’; elseif ($n > 1000000000) return round(($n/1000000000), 2).’ billion’; elseif ($n > 1000000) return round(($n/1000000), 2).’ million’; … Read more

Parse currency into numbers in Python

Below is a general currency parser that doesn’t rely on the babel library. import numpy as np import re def currency_parser(cur_str): # Remove any non-numerical characters # except for ‘,’ ‘.’ or ‘-‘ (e.g. EUR) cur_str = re.sub(“[^-0-9.,]”, ”, cur_str) # Remove any 000s separators (either , or .) cur_str = re.sub(“[.,]”, ”, cur_str[:-3]) + … Read more