Can you cut and paste the output you're getting here? Please enclose in Code tags to preserve formatting.
Gurtej Grewal wrote:I tried this initially but with different lengths of integers the format isn't maintained.
Carey Brown wrote:
That is a locale specific feature; the comma tag produces a comma as a thousands separator in Britain, North America, Australia, etc. In most of the rest of Europe it will use a dot. In India, it may put the thousands separator in different places.
G Atwal wrote:. . . and every 3 numbers separated with commas.
Formatter doesn't seem to have a currency symbol flag. It might be necessary to use the old way to format numbers, which you can find in the Java™ Tutorials (link 1 and link 2): NumberFormat#getCurrencyInstance().
. . . dollar symbol. . . .
I tried it and it didn't.
A few minutes ago, I wrote:. . . In India, it may put the thousands separator in different places. . . .
I can't remember when I last used NumberFormat rather than printf() and similar.
MyJShell wrote:jshell> NumberFormat format = NumberFormat.getCurrencyInstance(Locale.US);
format ==> java.text.DecimalFormat@67500
$20 ==> "$1,234,567.89"
Piet Souris wrote:Wow, overwhelming ideas!
I thought the priginal problem was that OP wanted the $ signs not to align.
. . . should the $-signs be aligned? . . .
Campbell Ritchie wrote:Yes, you can implement that as a record, but records are implicitly final classes, so my idea about nested classes wouldn't work at all well.