-1
String abc=11235.271;
Float.parsefloat(abc);

o/p 11235.271 no data loss

while as in

String abc=58996.706;
Float.parsefloat(abc);

o/p 58996.707

.001 is getting added after decimal

Can anyone pls help me on this

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
Sudarshan Bhatt
  • 105
  • 1
  • 6
  • Simply, float is less precize than decimal. Read this http://stackoverflow.com/questions/618535/difference-between-decimal-float-and-double-in-net – Djuro May 12 '17 at 06:49

1 Answers1

0

consider using a double or bigDecimal:

String abc2 = "58996.706";
System.out.println(Double.parseDouble(abc2));
System.out.println(new BigDecimal(abc2));
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97