anilreddy76
08-23-2007, 08:33 PM
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
Aradon
08-23-2007, 08:45 PM
You can do this with a NumberFormat and DecimalFormat
NumberFormat (http://java.sun.com/j2se/1.4.2/docs/api/java/text/NumberFormat.html)
DeciamlFormat (http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html)
Tutorial (http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html)
On the first tutorial page it should show you how to do it for comma's.
amitthechosen1
08-24-2007, 05:03 AM
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
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.
amitthechosen1
08-29-2007, 05:40 AM
well there wasnt any wrong in that i suppose.
Hence posted.