dragonpeng200811111 2014-05-15 05:25
浏览 226
已采纳

MySQL中的货币格式

I am pretty new to all of this and I couldn't find an answer worded this way when searching. I have a database with currency in it, in mysql it doesn't allow me to format the field to be in currency. Is there a way in PHP to format the field to format the text into a currency format so it looked like $5,250,000 instead of 5250000.

Print "<td><center>".$row['ContractM']."</centre></td> ";}

Above is the line that I want to be in currency format, how would I go about formatting it?

Thanks for your help.

  • 写回答

5条回答 默认 最新

  • dongxiee0744 2014-05-15 06:09
    关注

    Here. You can do this:

    $unitcost=number_format($row['ContractM']); /* Format Number */
    
    Print "<td><center>$ ".$unitcost."</centre></td> "; /* Echo result */
    

    If you want to include cents (two decimal places after the whole number):

    $unitcost=number_format($row['ContractM'],2); /* Format Number with decimal point */
    
    Print "<td><center>$ ".$unitcost."</centre></td> "; /* Echo result */
    

    Better also if you declare your ContractM row in your table as INT or DOUBLE.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器