Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float value changes after writing to realm even for integer part of the complete number #1589

Closed
gauravbordoloi opened this issue Dec 1, 2023 · 1 comment

Comments

@gauravbordoloi
Copy link

gauravbordoloi commented Dec 1, 2023

How frequently does the bug occur?

Always

Description

The following issue was raised for realm javascript (realm/realm-js#6293) but it was also happening for realm-kotlin as we faced the same issue.

Float value changes after writing to realm even for integer part of the complete number

import Realm from "realm"

class TData extends Realm.Object {
    static schema = {
        name: "CategoryModel",
        properties: {
            b: "string",
            a: "double",
            c: "float",
        },
        primaryKey: 'b',
    }
}

const db = {
    //path: DB_PATH,
    schema: [TData]
}

let realm = await Realm.open(db);

let p = `${Date.now()}`

let v = 1628899821

realm.write(() => {
    realm.create(TData, { a: v, c: v, b: p })
})

console.log(realm.objectForPrimaryKey(TData, p).toJSON())![image](https://github.com/realm/realm-kotlin/assets/23193185/05c55cbd-f731-496f-8385-c614bc88f82d)

Stacktrace & log output

No response

Can you reproduce the bug?

  • select --

Reproduction Steps

No response

Version

1.12.0

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android

Build environment

Android Studio version: ...
Android Build Tools version: ...
Gradle version: ...

@nirinchev
Copy link
Member

As mentioned in the JS answer, the issue is related to the fact you're using a 32-bit float to represent ~31-bit integer value. This is not possible and you need to use a larger data structure.

@nirinchev nirinchev closed this as not planned Won't fix, can't repro, duplicate, stale Dec 4, 2023
@sync-by-unito sync-by-unito bot closed this as completed Feb 17, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants