#[SOLVED] double attributes are saved as int

20 messages · Page 1 of 1 (latest)

crystal wigeon
#

Hi, I don't know if it's my fault but I save the values as double but they are saved as int.

#

which causes me an error, because I expect a double value

#

As far as I can see, appwrite approximates the closest value, but that's not what I want. Is there any way to disable this approximation?

golden flower
#

Hi - let me take a look at this

golden flower
#

are you writing values in console?

#

can you please elaborate a bit about how you are storing values so i can see if this could be a bug?

crystal wigeon
#

Either way, it doesn't save as a double value. Either saving from the console for example default value or values saved from the project

#

although creating a document from the console does work

golden flower
#

we tried replicating this and we are able to make the document with decimal values. Can you elaborate on what are you exactly trying to do (the steps) and/or code piece so we can see what's happening

crystal wigeon
#

I already found the reason. It is because when we save a value, for example 25.0, it is saved as 25.
But if 25.1 is saved if the double value is respected.

#

but this generates problems for me because I would have to be converting the values obtained to double

golden flower
#

Tagging @fickle bay here

fickle bay
#

This might be an interesting issue. I am pretty sure on the backend its handled properly, but Javascript/the browser uses the same data type for both int/float values.

So it is properly saved into the backend, but the moment Javascript gets it from the Database, it makes it an integer. On many other languages it should be interpreted correctly.

crystal wigeon
#

Mmm I understand. And it is not possible to make a condition .endsWith(".00") and if it is fulfilled, apply a toFixed?

#

or the best solution would be to convert the values obtained from the database back to double? although it should be an unnecessary task

next hollow
#

From the Appwrite side, it is expected to return something like:

{
  "price": 333
}

JSON is JavaScript and JavaScript does not differentiate between int or double. As such, whole numbers will be simplified to drop the decimals.

In a language that differentiates the two, you'll have to convert it accordingly. For example, you can do json["price"]?.toDouble().

#

or you can use the num type

crystal wigeon
#

[SOLVED] double attributes are saved as int