【发布时间】:2017-11-22 03:05:22
【问题描述】:
我正在编码产品库存。现在我正在计算或将项目转换为更大的单元。
例如: 产品A:1盒=12瓶
用户在添加交易时可以输入3盒13瓶这样的数据。产品 A 的新值将是 3 boxes and 13 bottles in storage。数据将保存到数据库tbl_transaction。
我怎样才能像4 boxes and 1 bottle in storage这样将项目作为一个整体自动翻转/转换以添加到我的tbl_storage中?
这个公式我试过了,但是瓶数在小数点后恐怕不准确。
$bottles = 13;
$box = 12;
$remaining_in_bottle = number_format($bottles / $box);// this will only convert the bottle into box (also tried float but not sure what I am doing)
$total_box = 3 + ???;
echo $total_box." boxes and ".$remaining_in_bottle ." bottles in storage
【问题讨论】:
标签: php floating-point decimal