codewithbawo
codewithbawo

Reputation: 91

Convert string to a float in runtime

I converted a string to a float value, and I am setting the float value in runtime to realm database. This is what I did

float appVersion = Float.parseFloat(BuildConfig.VERSION_NAME); managedMetadata.setAppVersion(appVersion);

But then instead of getting the right value which is 1.31 on the database, I was getting 1.3099999... Please how can I work around this? I am new to android. Thanks

Upvotes: 0

Views: 155

Answers (1)

Harry Coder
Harry Coder

Reputation: 2740

Why do you want to convert your app version to a float? An app version do not represent a float value, so you should keep it like this. Read this : https://semver.org/ and Android version code

Upvotes: 1

Related Questions