Dividing two Decimal128 produces weird results

I have this dividing operation which returned result is ok but the value synced to Atlas backend is wrong:

let value1: Decimal128 = 70
let value2: Decimal128 = 1.09
value1 / value2 = +6422018348623853211009174311926606E-32

The value synced to server is: 12.29721490089025582478677982706510

Any ideea what is the issue?

Hi @horatiu_anghel, it looks like you are using the swift SDK? Which version are you running? We had an issue with Decimal128 values if they had more than 19 significant digits, but that has been fixed for a while now.

1 Like

Hi @James_Stone, thank you for your reply! Yes, I am using swift SDK, last version 10.28.1.

@horatiu_anghel thanks! Could you please open an issue in GitHub - realm/realm-swift: Realm is a mobile database: a replacement for Core Data & SQLite with a code sample of how you are storing the value? The team there should be able to help figure out what is going on.

1 Like

Ok! I will open an issue. Thank you!

1 Like

I am not able to duplicate this issue.

I created a model (Swift)

class TestClass: Object {
   @Persisted var someDecimal: Decimal128 = 0.0

then populated it

let test = TestClass()
let value1: Decimal128 = 70
let value2: Decimal128 = 1.09
test.someDecimal = value1/value2

and stored it (sync’ing to the server)

When I read the object back and print the value of someDecimal


I get


Perhaps it’s how the model is set up? Can you post that so we can take a look?

Hi @Jay,

If you try to sync that value on another device is the correct one? Or using MongoDB Compass to see the value stored on Atlas.

On device where the value was created everything is ok.

Sure enough… Either accessing/syncing from another fresh device or wiping the current local data and resync’ing results in incorrect data.

Here’s the git link

1 Like