numberformat

Format negative amount of USD with a minus sign, not brackets (Java)

How do I get NumberFormat.getCurrencyInstance() to print negative USD currency values with a minus sign? ...

Java localizing number formatting

Java uses period in decimals, e.g. 1/2 = 0.5 Is there any way to make it use comma instead, as in 1/2 = 0,5? And not to use comma for thousands (as in one hundred thousand = 100,000) but use space instead (100 000)? When it comes to output I suppose I could use all sorts of string format functions, but the problem is input (JTable). ...

J2ME - number format

Hi! I need to format decimal numbers with patterns in J2ME just like java DecimalFormat. I see an option to port Format/NumberFormat/DecimalFormat. Can you suggest ready to use implementation or library? Thanks! ...

GWT NumberFormat problems with high precision decimals

Hello everyone. I'm using GWT 2.0 and when I try to use NumberFormat to format a Double the results are not as expected: NumberFormat format = NumberFormat.getFormat( "#.########" ); Double d = new Double("0.256281093911"); format.format(d); formatted string: 0.02147484 As you can see the formatted value is wrong (this can be seen in...

Efficient algorithm in t-sql to mimic int.ToString("D4");

int i=99; string s=i.ToString("D4"); //s=="0099" Please advice on efficient implementation of preceding zeroes of numbers in textual format. ...

How to get the same value as the user is seeing from a JFormattedTextField?

I'm using a NumberFormatter and JFormattedTextField, but the .getValue() doesn't return the same value as the user is seeing. I think the input-string is parsed using NumberFormats parse-method, and I get the Numberformat from NumberFormat.getNumberInstance(); with the actual Locale. So I don't think I easily can extend it and write my ...

java generate regular expression from localized NumberFormat

Is there any clean way to generate a regular expression that will match values formatted with a locale-configured java NumberFormat? Or some library that will do so? This is in a web-based app & I want to pass the regex out to the jsp page for javascript validation on numeric fields. Locale varies on a per-user basis & I'd like to not...

Is it possible to set the CultureInfo for an .NET application or just a thread?

I've an application written in C# which has no GUI or UI, but instead writes files that are parsed by another application (in XML and others). I have a customer whose CultureInfo has the NumberDecimalSeparator set to a comma, which causes parsing errors with floating point numbers (PI would end up as 3,1415). I'd like a way to set the ...

Strange behaviour of NumberFormat Java

Hello, I have the following code to parse a String variable called str. NumberFormat formatter = NumberFormat.getInstance(); Number number = formatter.parse(str); I want to catch the Exception thrown when str is not a number just to validate it. The problem I have is that it does't always throws the ParseException expected. When the ...

In Java, why does the decimal separator follow the Locale's language, not its country, and, more importantly, how does one override it?

Hello, I'm working on an international project and have observed that, in Java, the choice of the decimal separator is based on the Locale's language, not its country. For example: DecimalFormat currencyFormatter = (DecimalFormat) NumberFormat.getInstance(new Locale("it","IT")); System.out.println(currencyFormatter.format(-123456.78));...

Java Currency Number format

Hi, Is there a way to format a decimal as following: 100 -> "100" 100.1 -> "100.10" i.e. if it is round omit the decimal part otherwise always show 2dp. Thxs. ...

PowerShell, formatting values in another culture

Is there an easy way in PowerShell to format numbers and the like in another locale? I'm currently writing a few functions to ease SVG generation for me and SVG uses . as a decimal separator, while PowerShell honors my locale settings (de-DE) when converting floating-point numbers to strings. Is there an easy way to set another locale f...

Can you get access to the NumberFormatter used by ICU MessageFormat

This may be a niche question but I'm working with ICU to format currency strings. I've bumped into a situation that I don't quite understand. When using the MesssageFormat class, is it possible to get access to the NumberFormat object it uses to format currency strings. When you create a NumberFormat instance yourself, you can specify a...

How to prefix a positive number with plus sign in PHP

I need to design a function to return negative numbers unchanged but should add a + sign at the start of the number if its already no present. Example: Input Output ---------------- +1 +1 1 +1 -1 -1 It will get only numeric input. function formatNum($num) { # something here..perhaps a regex? } This f...

DecimalFormat and Double.valueOf()

Hello. I'm trying to get rid of unnecessary symbols after decimal seperator of my double value. I'm doing it this way: DecimalFormat format = new DecimalFormat("#.#####"); value = Double.valueOf(format.format(41251.50000000012343)); But when I run this code, it throws: java.lang.NumberFormatException: For input string: "41251,5" ...

Ab Initio - Formatting a number in Left alignment

I have a requirement in Ab Initio to format a number in left alignment. I shouldn't be using String conversion (as Strings are left aligned by default), as it might cause compatibility problems in the other end. For example, if my Field has 7 bytes length, and I'm getting only two digits as my input, then these two digits should go into...

When using the getInstance() method of the abstract java.text.NumberFormat class, what is the actual class of the return value?

This question expands upon the one at abstract-class-numberformat-very-confused-about-getinstance. I feel that this question is different enough to merit being asked on its own. In the answers to that question, it was stated that a code statement such as NumberFormat en = NumberFormat.getInstance(Locale.US); returns an object that is...

php add thousandseperator without adjusting decimal places

I'm looking for a way to use the php number_format function or something similar that will add the thousand seperator but will leave any decimal part of the number intatct without and formatting of this. For example: 39845.25843 => 39,845.25843 347346.8 => 347,346.8 1000000 = > 1,000,000 Thanks ...

setlocale to fr-FR in PHP and number formatting

Hi, I am trying to create a French version of one of my sites. I have set setlocale(LC_ALL, 'fr_FR'); at the top of my page, and using strftime I am displaying dates correctly in the French style. However I am having some problems with a number. Part of the page uses data I am getting from a Web Service. I am assigning a returned value ...

ChoiceFormat.setChoices confusion about format parameter type and documentation

From the java.text.ChoiceFormat API: setChoices(double[] limits, String[] formats): Set the choices to be used in formatting. Parameters: limits - contains [...] formats - are the formats you want to use for each limit. They can be either Format objects or Strings. When formatting with object Y, if the object is a ...