gpt4 book ai didi

java - 使用bigdecimal在mysql中存储百分比值

转载 作者:行者123 更新时间:2023-11-29 08:52:54 25 4
gpt4 key购买 nike

如何使用 BigDecimal 在 MySQL 中存储百分比值?

我使用以下代码来执行此操作:

chngePer=new BigDecimal(st.nextToken().trim().replace("%", "")).divide(BigDecimal.valueOf(100));

但它给了我 numberFormatException。

我正在使用 CSV 文件并将其每个值存储在 stringTokenizer st 中。它的值之一是-0.45%。如何将其存储在数据库中?

StringTokenizer st=new StringTokenizer(nextLine, ",");
chngePer=new BigDecimal(st.nextToken().trim().replace("%", "")).divide(BigDecimal.valueOf(100));

编辑: token 内容

  • “塔塔咨询公司”
  • 654914
  • 5
  • +2.2999
  • “+0.19%”
  • “2012 年 5 月 23 日”

最佳答案

也许您需要删除引号。

关于java - 使用bigdecimal在mysql中存储百分比值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10715240/

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