简体   繁体   English

在 greendao 中用于 Decimal(10,2) 的最佳数据类型是什么

[英]What is the best data type to use in greendao for Decimal(10,2)

I am trying to migrate my old db written in sqlite to greendao ORM , I need to set the column to DECIMAL(10,2) for storing the price of the item.我正在尝试将用 sqlite 编写的旧数据库迁移到 greendao ORM ,我需要将该列设置为 DECIMAL(10,2) 以存储商品的价格。 What is the equivalent data type that I can use.我可以使用的等效数据类型是什么。 DO I need to use a custom data type for that?我需要为此使用自定义数据类型吗?

There are a couple of options, use a long value representing the smaller unit.有几个选项,使用代表较小单位的长值。

Then if you had a long price property, you could get the big unit using price / 100 and the small unit via price % 100 .然后,如果您有一个long price属性,您可以使用price / 100获得大单位,通过price % 100获得小单位。 Like this you can still use price for regular integer calculation.像这样,您仍然可以使用price进行常规整数计算。

For formatting, don't forget an extra '0' for the small unit if it is single digit.对于格式化,如果小单位是个位数,请不要忘记额外的“0”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM