I have a string with some numeric value.
I want to format it in a way where hundreds are comma separated and the number is having $ dollar sign before it.
e.g. 12345 should be formatted to $ 12,345.00
I tried the below code without dollar sign:
new java.text.DecimalFormat(#,##0.00).format.(myString)
and the below one with dollar sign:
new java.text.DecimalFormat($ #,##0.00).format.(myString)
However, both are giving error.
What is the right way to achieve this format ?
This is a part of jasper report jrxml where I want to avoid "null" on the report and thus inserting the below code:
<textField isBlankWhenNull="false" isStretchWithOverflow="true">
<reportElement stretchType="RelativeToTallestObject" x="1350" y="0" width="150" height="30"/>
<textElement/>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{myString}!=null?new java.text.DecimalFormat(#,##0.00).format.($F{myString}):"Unavailable"]]></textFieldExpression>
</textField>
Where myString results from a query and is declared in jrxml as:
<field name="myString" class="java.lang.String"/>
Earlier myString was declared as BigDecimal, but then comparison operator ?= was not working.
If the currency value is not available, I want to print "unavailable" on the report instead of default "null". Else, I want the number to be properly formatted as described above.
How to resolve this issue?
Thanks for reading.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…