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
Jay
(Jason Wooten)
July 1, 2022, 7:36pm
6
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
print(test.someDecimal)
I get
+6422018348623853211009174311926606E-32
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.
Jay
(Jason Wooten)
July 3, 2022, 1:24pm
8
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
opened 05:56PM - 29 Jun 22 UTC
closed 11:34AM - 01 Aug 22 UTC
T-Bug
O-Community
### How frequently does the bug occur?
All the time
### Description
I am havi… ng a strange issue when dividing two Decimal128 values. The result on device and printed on console is ok but the value synced to Atlas backend is wrong. I believe it is related to the significant digits.
I have this two values:
```
@Persisted var grossPrice: Decimal128 = 70
@Persisted var vatValue: Double = 1.09
grossPrice / Decimal128(floatLiteral: vatValue) = +6422018348623853211009174311926606E-32
```
The value stored on server is: ```12.29721490089025582478677982706510```.
On the device where the operation is made, everything is ok but, on other synced devices, all the results are wrong.
### Stacktrace & log output
_No response_
### Can you reproduce the bug?
Yes, always
### Reproduction Steps
_No response_
### Version
10.28.1
### What SDK flavour are you using?
MongoDB Realm (i.e. Sync, auth, functions)
### Are you using encryption?
Yes, using encryption
### Platform OS and version(s)
iOS 15.5
### Build environment
Xcode version: 13.4.1
1 Like