douchiwan1503 2012-04-24 08:07
浏览 19
已采纳

在MySQL表中插入之前格式化十进制?

I imported information from txt files. I have 3 files, and one field from this file is a price with different format.

The format on column is DECIMAL(12,5)

file 1 -> $price_1 = 000000000000024.99

file 2 -> $price_2 = 25476,99

file 3 -> $price_3 = 3,768.44

Before inserting in mySQL table I using folowing script:

For file 1

$price = (real)number_format($price_1 , 2, '.', '');

For file 2

$price = (real)str_replace(",", ".", $price_2);

For file 3

$price = (real)str_replace(",", "", price_3);

I do't know if this format is correct before I insert a record in the table? If there is any other solution I'll be very grateful. I apologize for my English. Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongshun1884 2012-04-24 08:16
    关注

    You can use printf or sprintf php functions to get numbers in proper format.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题