Currency validation

You could use a regexp: var regex = /^\d+(?:\.\d{0,2})$/; var numStr = “123.20”; if (regex.test(numStr)) alert(“Number is valid”); If you’re not looking to be as strict with the decimal places you might find it easier to use the unary (+) operator to cast to a number to check it’s validity: var numStr = “123.20”; var … Read more

In angular 2, how to display a number as two decimal rounded currency?

Use this code. Here is a working example http://plnkr.co/edit/xnN1HnJtTel6WA24GttR?p=preview {{num | currency:’USD’:true:’1.2-2′}} Explanation : number_expression | number[:digitInfo] Finally we get a decimal number as text. Find the description. number_expression: An angular expression that will give output a number. number : A pipe keyword that is used with pipe operator. digitInfo : It defines number format. … Read more

What is the standard for formatting currency values in JSON?

I don’t know if it’s the best solution, but what I’m trying now is to just pass values as strings unformatted except for a decimal point, like so: “amount”: “1234.56” The app could easily parse that (and convert it to double, BigDecimal, int, or whatever method the app developer feels best for floating-point arithmetic). The … Read more

How to properly format currency on ios

You probably want something like this (assuming currency is a float): NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle]; NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithFloat:currency]]; From your requirements to treat 52 as .52 you may need to divide by 100.0. The nice thing about this approach is that it will respect the current locale. … Read more

Is there a way to round numbers into a reader friendly format? (e.g. $1.1k) [closed]

Here is a simple function to do it: function abbrNum(number, decPlaces) { // 2 decimal places => 100, 3 => 1000, etc decPlaces = Math.pow(10,decPlaces); // Enumerate number abbreviations var abbrev = [ “k”, “m”, “b”, “t” ]; // Go through the array backwards, so we do the largest first for (var i=abbrev.length-1; i>=0; i–) … Read more

Regex currency validation

The RegEx // Requires a decimal and commas ^\$?(([1-9]\d{0,2}(,\d{3})*)|0)?\.\d{1,2}$ // Allows a decimal, requires commas (?=.*\d)^\$?(([1-9]\d{0,2}(,\d{3})*)|0)?(\.\d{1,2})?$ // Decimal and commas optional (?=.*?\d)^\$?(([1-9]\d{0,2}(,\d{3})*)|\d+)?(\.\d{1,2})?$ // Decimals required, commas optional ^\$?(([1-9]\d{0,2}(,\d{3})*)|0)?\.\d{1,2}$ // *Requires/allows X here also implies “used correctly” The RegEx Breakdown When the optional parts are too liberal, we need to look ahead and guarantee there’s a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)