I am getting a string with follwing formats 23434 2.32453 223,324,343.34532424 324,343.34532424 2.3453E-01 32,456.9 0 1.0 Note:The Number can be negative also. First I want to check whether the number is postive or negative Secondly I want to round the value to two decimal place. Thirdly I want to display the number in the million format. Regards Asheesh
Eric Edwards
Ranch Hand
Joined: Feb 12, 2000
Posts: 60
posted
0
Originally posted by Asheesh_talwar: I am getting a string with follwing formats 23434 2.32453 223,324,343.34532424 324,343.34532424 2.3453E-01 32,456.9 0 1.0 Note:The Number can be negative also. First I want to check whether the number is postive or negative Secondly I want to round the value to two decimal place. Thirdly I want to display the number in the million format. Regards Asheesh
Try this! example: double x = 134.5678923; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); String fx = nf.format(x); // this will print with two decimal places. java.text has all kinds of number formatting available.
asheesh talwar
Ranch Hand
Joined: Dec 10, 2000
Posts: 31
posted
0
Eric my problem is the coma between digits. The i/p string can be in million format(i.e 234,568.878) or can be with out it(ie 343445.34) but I have to show it in million format. Lets Look again what I need i/p o/p 0 0.00 23.347876 23.35 234,456.02334 234,456.02 234567 234,567.00 2345.456 2,345.46 Note: the number can be negative also. I am able to solve this by a very lenghty method which I think is a waste in java(which has a ocean of readymade classes). If any one has a short & to the point answer then it will be of great help. Thanx Asheesh
Praveen Jadhav
Greenhorn
Joined: Nov 28, 2000
Posts: 7
posted
0
hi asheesh here it the best possible code according to me for the query u have told
convert the above code in proper function and u can use it presently , u have pass command line argument to get ur output
Praveen Jadhav<BR>Mumbai
asheesh talwar
Ranch Hand
Joined: Dec 10, 2000
Posts: 31
posted
0
Hi praveen thanx a lot. I was able to do it by one more method. DecimalFormat df = new DecimalFormat("#,##0.00"); s1 = df.format(lvar);
Regards Asheesh
sridhar chenn
Greenhorn
Joined: Mar 19, 2003
Posts: 2
posted
0
hi can u help me out in extending the number format to INR rep. 1,25,000.00 for one lakh, 25 thou...
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Welcome to JavaRanch, sridhar! According to The DecimalFormat Class Documentation:
The grouping size is a constant number of digits between the grouping characters, such as 3 for 100,000,000 or 4 for 1,0000,0000. If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So "#,##,###,####" == "######,####" == "##,####,####".