2

I am creating a small Android app in which I am doing some math calculation, using both Java and SQLite. The issue is that the SQLite function round(...) return different value than Java Math.round(..) in some devices.

To be more precise, my goal is to round double numbers to two decimal places, In Java I used this method:

public static double round2(double value){
   value= Math.round(value* 100.0) / 100.0;
   return value;
}

in SQLite my query is : SELECT ROUND(total, 2)

running the above code, the obtained result are as follow:

in Java rounding 66.875 return 66.88

For the SQL query, in some Android device, the result is 66.88 (Android API 28) , while it is 66.87 in others (API 24).

Anyone has encounter the same situation, please i want to find a way to obtain same rounding in Java and SQLite in all devices whatever the device API is.

YoucefB
  • 21
  • 2
  • 1
    see https://stackoverflow.com/questions/2421189/version-of-sqlite-used-in-android about getting the DB version. It may be related to the DB version – balderman Dec 10 '20 at 19:41
  • 1
    @balderman I know that this is related to the version of SQLite DB which depends on the device SDK, but what is the solution to get same result in Java side and SQLite side in all different devices – YoucefB Dec 10 '20 at 19:51
  • 4
    If you want to control it - bring your sqlite with your app. See https://github.com/graviton57/SqliteAndroid – balderman Dec 10 '20 at 19:54
  • This seem to be a little complicated, I am looking for a kind of command or directives that let SQLite behave in the same manner independently from the version. – YoucefB Dec 10 '20 at 20:01
  • How is `total` calculated? – Shawn Dec 10 '20 at 22:08
  • @Shawn assume it a field in the table or calculated from other fields, this is has no effect, what we want is to round it in normalized way – YoucefB Dec 11 '20 at 20:16

0 Answers0