gpt4 book ai didi

java - 在 SQlite android 数据库中存储货币

转载 作者:IT王子 更新时间:2023-10-29 06:22:31 36 4
gpt4 key购买 nike

我正在尝试将货币值存储在 android 的 sqlite 数据库中。我不认为 int 会在这里使用。我听说可以使用Bigdecimal。如果有人能告诉我它应该用于将值发送到 sqlite 数据库的方式。

最佳答案

将 BigDecimal 存储为字符串。

您可以使用 toPlainString() 方法。

BigDecimal b = new BigDecimal();
String s = b.toPlainString();

然后,当您从数据库中提取它时,您可以创建一个新的 BigDecimal。

BigDecimal c = new BigDecimal(String s)

信不信由你,SQLite 3.0 将所有数据类型存储为字符串,即使您说它应该是一个整数。看看this web page from the official SQLite website并向下滚动到“ list 类型和 BLOB 支持”部分。它讨论了如何让您将字符串存储在其他类型的列中。

关于java - 在 SQlite android 数据库中存储货币,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9187586/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com