Using Realm.io to store money values

前端 未结 4 1459
被撕碎了的回忆
被撕碎了的回忆 2021-01-18 09:11

I\'m starting to play with Realm.io in an Android app that I\'m writing. In one of my data objects, I\'m required to store a currency value. Previously I had stored the valu

4条回答
  •  遥遥无期
    2021-01-18 09:37

    Emanuele from Realm here.

    You are right, using floats or doubles for currency is a bad idea.

    We don't support BigDecimal for now, and before we do we will have to see how that plays in relation to all other language bindings since we want realm files to be compatible across all the supported platforms.

    Christian's idea is good, but I see the conversion to and from String to be a bit slow. If you don't need the arbitrary precision property of BigDecimal you could use long and multiply/divide by the factor your required precision calls for. This would also save a lot of space in terms of the size of the Realm file since integer values are bit packed.

提交回复
热议问题