Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8063689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:07:31+00:00 2026-06-05T11:07:31+00:00

I have a string with some numeric value. I want to format it in

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:07:33+00:00Added an answer on June 5, 2026 at 11:07 am

    The correct expression is:

    new java.text.DecimalFormat("$ #,##0.00").format(Double.valueOf($P{strParam}))
    

    The working sample for java.lang.Integer and java.lang.String:

    <?xml version="1.0" encoding="UTF-8"?>
    <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="format_as_current" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
        <parameter name="intParam" class="java.lang.Integer">
            <defaultValueExpression><![CDATA[12345678]]></defaultValueExpression>
        </parameter>
        <parameter name="strParam" class="java.lang.String">
            <defaultValueExpression><![CDATA["12345678.95"]]></defaultValueExpression>
        </parameter>
        <title>
            <band height="79" splitType="Stretch">
                <textField>
                    <reportElement x="137" y="18" width="291" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[new java.text.DecimalFormat("$ #,##0.00").format($P{intParam})]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="137" y="48" width="291" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[new java.text.DecimalFormat("$ #,##0.00").format(Double.valueOf($P{strParam} != null && $P{strParam}.length() > 0 ? Double.valueOf($P{strParam}) : 0))]]></textFieldExpression>
                </textField>
            </band>
        </title>
    </jasperReport>
    

    The result will be (preview in iReport):

    The result in *iReport*

    Note:
    You should also add check for null.

    You can also use pattern property of textField for formatting data.

    The sample:

    <?xml version="1.0" encoding="UTF-8"?>
    <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="format_as_current" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
        <parameter name="intParam" class="java.lang.Integer">
            <defaultValueExpression><![CDATA[12345678]]></defaultValueExpression>
        </parameter>
        <parameter name="strParam" class="java.lang.String">
            <defaultValueExpression><![CDATA["12345678.95"]]></defaultValueExpression>
        </parameter>
        <title>
            <band height="148" splitType="Stretch">
                <textField pattern="$ #,##0.00">
                    <reportElement x="218" y="99" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$P{intParam}]]></textFieldExpression>
                </textField>
                <textField pattern="$ #,##0.00">
                    <reportElement x="218" y="119" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$P{strParam} != null && $P{strParam}.length() > 0 ? Double.valueOf($P{strParam}) : 0]]></textFieldExpression>
                </textField>
            </band>
        </title>
    </jasperReport>
    

    The result will be the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a String with some value. I want to iterate over all classes
I have a string[] in which every elements ends with some numeric value. string[]
suppose I have this string: some striinnngggg <a href=something/some_number>linkk</a> soooo <a href=someotherthing/not_number>asdfsadf</a> I want
HI, I have some string from XML file, and I I want to replace
I have some string of characters (all are only alphabetic and rare newlines, no
I have some String[] arrays, for example: ['a1', 'a2'] ['b1', 'b2', 'b3', 'b4'] ['c1']
I have some string like this: 04:51 05:09 05:29_ 05:49 06:09 06:29 06:49_ 07:09
I have a string: [\n['-','some text what\rcontains\nnewlines'],\n\n trying to parse: Regex.Split(@[\n['-','some text what contains
I have a string contaning some html markup, like this: var html = <div>
I have some random string, let's say : s = This string has some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.