Formatting Currencies in Foreign Locales in Java

Try using setCurrency on the instance returned by getCurrencyInstance(Locale.GERMANY) Broken: java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(java.util.Locale.GERMANY); System.out.println(format.format(23)); Output: 23,00 € Fixed: java.util.Currency usd = java.util.Currency.getInstance(“USD”); java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(java.util.Locale.GERMANY); format.setCurrency(usd); System.out.println(format.format(23)); Output: 23,00 USD

WPF StringFormat={0:C} showing as dollars

I’m not sure if this has been fixed in .NET 4, but WPF has never picked up the current culture when rendering things like currency or dates. It’s something I consider a massive oversight, but thankfully is easily corrected. In your App class: protected override void OnStartup(StartupEventArgs e) { FrameworkElement.LanguageProperty.OverrideMetadata( typeof(FrameworkElement), new FrameworkPropertyMetadata( XmlLanguage.GetLanguage( CultureInfo.CurrentCulture.IetfLanguageTag))); … 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

Format a number with leading sign

Use a negative subpattern, as described in the javadoc for DecimalFormat. DecimalFormat fmt = new DecimalFormat(“+#,##0.00;-#”); System.out.println(fmt.format(98787654.897)); System.out.println(fmt.format(-98787654.897)); produces (in my French locale where space is the grouping separator and the comma is the decimal separator) : +98 787 654,90 -98 787 654,90

Get currency symbol in PHP

First of all, there is no international global currency symbol table, that anyone on the planet could read and understand. In each region/country the currency symbols will differ, that`s why you must determine them based on who is reading, using the browser / user locale. The correct way is as you guessed, using NumberFormatter::CURRENCY_SYMBOL, but … Read more

Java double comparison epsilon

You do NOT use double to represent money. Not ever. Use java.math.BigDecimal instead. Then you can specify how exactly to do rounding (which is sometimes dictated by law in financial applications!) and don’t have to do stupid hacks like this epsilon thing. Seriously, using floating point types to represent money is extremely unprofessional.

Format a double value like currency but without the currency sign (C#)

If the currency formatting gives you exactly what you want, clone a NumberFormatInfo with and set the CurrencySymbol property to “”. You should check that it handles negative numbers in the way that you want as well, of course. For example: using System; using System.Globalization; class Test { static void Main() { NumberFormatInfo nfi = … Read more