Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Displaying integer in JSP..

    Hi,

    I've a long integer value in jsp and I need to display commas between groups of thousands, eg: 176,000.

    Please advise how we can do this in jsp.

    Thanks,
    Kumar

  • #2
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    You can do this with a NumberFormat and DecimalFormat

    NumberFormat
    DeciamlFormat

    Tutorial

    On the first tutorial page it should show you how to do it for comma's.
    "To iterate is human, to recurse divine." -L. Peter Deutsch

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi Anil,
    I tried the solution suggested by Aradon.
    I made a sample file and tried working with that.
    Below is the code for the file Number.java

    import java.text.NumberFormat;

    public class Number {

    public static void main(String args[]){

    long num = 1760000;
    String myString= NumberFormat.getInstance().format(num);
    System.out.println(myString);
    }
    }


    --> On running this code, you get the output as
    1,760,000

    I have compiled and run this code and its working absolutely the way you wanted it.

    Regards,
    Amit

  • #4
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    865
    Thanks
    7
    Thanked 29 Times in 28 Posts
    amitthechosen1, seems that Aradon already provided a satisfactory answer....plus, anilreddy76 was not asking for console solution???

    ohh..never mind, if it pleases you to show off your skills....then good on you.

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post
    well there wasnt any wrong in that i suppose.
    Hence posted.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •