Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

float value

Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks silly....but can't figure out. I need to get a float type value from a string value.

Why is the float value rounding up. For example

when i give 123456.488 it results in 123456.484
when i give 988800.45 it results in 988800.44

String sFloatSales = "123456.488";
float fFloatSales1 = Float.parseFloat(sFloatSales);
float fFloatSales2 = Float.valueOf(sFloatSales).floatValue();

Please reply.
Posts: 25965
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Float values only have 6 or 7 digits of accuracy anyway, so the differences you see there aren't significant. If they are significant to you then you should be using double instead of float.
Don't play dumb with me! But you can try this tiny ad:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic