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

Print Currency Number Format in PHP

The easiest answer is number_format(). echo “$ “.number_format($value, 2); If you want your application to be able to work with multiple currencies and locale-aware formatting (1.000,00 for some of us Europeans for example), it becomes a bit more complex. There is money_format() but it doesn’t work on Windows and relies on setlocale(), which is rubbish … Read more

Localize Currency for iPhone

NSNumberFormatter is definitely the way to go! You can set a NSLocale on the NSNumberFormatter, the formatter will automatically behave according to that locale. The default locale for a number formatter is always the currency for the users selected region format. NSDecimalNumber *someAmount = [NSDecimalNumber decimalNumberWithString:@”5.00″]; NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init]; [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; NSLog(@”%@”, … Read more

How to display Currency in Indian Numbering Format in PHP?

You have so many options but money_format can do the trick for you. Example: $amount=”100000″; setlocale(LC_MONETARY, ‘en_IN’); $amount = money_format(‘%!i’, $amount); echo $amount; Output: 1,00,000.00 Note: The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows. Pure PHP Implementation – Works on … Read more

How to format numbers as currency strings

Intl.NumberFormat JavaScript has a number formatter (part of the Internationalization API). // Create our number formatter. const formatter = new Intl.NumberFormat(‘en-US’, { style: ‘currency’, currency: ‘USD’, // These options are needed to round to whole numbers if that’s what you want. //minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1) … Read more

What class to use for money representation?

Never use a floating point number to represent money. Floating numbers do not represent numbers in decimal notation accurately. You would end with a nightmare of compound rounding errors, and unable to reliably convert between currencies. See Martin Fowler’s short essay on the subject. If you decide to write your own class, I recommend basing … Read more

Format currency without currency symbol

The following works. It’s a bit ugly, but it fulfils the contract: NumberFormat nf = NumberFormat.getCurrencyInstance(); DecimalFormatSymbols decimalFormatSymbols = ((DecimalFormat) nf).getDecimalFormatSymbols(); decimalFormatSymbols.setCurrencySymbol(“”); ((DecimalFormat) nf).setDecimalFormatSymbols(decimalFormatSymbols); System.out.println(nf.format(12345.124).trim()); You could also get the pattern from the currency format, remove the currency symbol, and reconstruct a new format from the new pattern: NumberFormat nf = NumberFormat.getCurrencyInstance(); String pattern = … Read more