我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

乘以字符串值

I have a string like this:

$price = "15.50";

And I would like to multiply it. Ex:

$price*$amount;

I tried something like this:

$Total = floatval($price)*$amount;

But I always get "30" as return. How can I code to get "31.00"?

Thanks a lot.

Try this...

$fltAmount = floatval($amount);
$fltPrice = floatval($price);
$Total = $fltAmount*$fltPrice

I found the answer here! http://www.php.net/manual/en/ref.var.php

You need to have float as datatype. This gets easily typecasted into int. So, do this!

$Total = floatval($amount) * floatval($price);

近期文章

  • Paypal和AngellEye Library:您必须只指定一个主接收器和至少一个辅助接收器
  • 目前从图像中删除html链接
  • 执行插入查询时出错
  • HHVM在NotFoundHttpException上中断
  • OpenCart - 如何在点击时重新加载验证码图像?
  • 这个扩展ASCII的一部分是什么编码?
  • PHP脚本完成后删除文件
  • PHP表单SQL格式错误
  • 正则表达式 - 替换存储元素中的空格
  • 使用CSS样式表格式化PHP值
  • 简单DELETE php pdo查询
  • 为什么php变量无法使用javascript循环?
  • 显示当前日期过去11个月的列表
  • 如何在php文件中更改php.ini设置
  • SELECT * FROM tbl WHERE col1 = $ var1和col2 = $ var2和col3 = $ var3
  • 当点击列表项时隐藏其他项目
  • 如何自动将用户配置文件数据添加到Wordpress中的联系表单
  • 使用admin-ajax.php的AJAX请求
  • 我如何删除弦中的针
  • [0-9] + .txt似乎不匹配带有数字名称的文本文件

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华