Php 只舍入变量的整数

Php 只舍入变量的整数,php,magento,Php,Magento,我正忙于一家网店,我有一个问题: 我显示产品的数量和产品的属性 比如: 2,4 cm 2,56 dm 现在我想对变量的数字进行四舍五入,但是如果我使用: $qty = round($_product->getBundle_qty()); 但是如果我使用:aantal=$\u product->getBundle\u qty()一切正常,但他不转 然后属性不再显示(dm、cm、m等) 有人能帮我吗?美元产品->getBunlde\u数量()实际上是双倍还是浮动?还是仅仅是一根绳子?在这种

我正忙于一家网店,我有一个问题:

我显示产品的数量和产品的属性

比如:

2,4 cm
2,56 dm
现在我想对变量的数字进行四舍五入,但是如果我使用:

$qty = round($_product->getBundle_qty());
但是如果我使用:
aantal=$\u product->getBundle\u qty()一切正常,但他不转

然后属性不再显示(dm、cm、m等)


有人能帮我吗?

美元产品->getBunlde\u数量()实际上是双倍还是浮动?还是仅仅是一根绳子?在这种情况下,您可以使用:

$qty = round(floatval($_product->getBundle_qty()));
编辑: 现在,如果你想把cm/dm放在字符串后面,我们可以将字符串在所有空格处分解,从而从字符串中创建一个数组。此数组中的最后一个值将是“cm”或“dm”文本

$qtyPieces = explode(" ", $_product->getBundle_qty()); //explode at the space
$qtyPiecesCount = count($qtyPieces); //count all pieces
$qty = round(floatval($_product->getBundle_qty())) . " " . $qtyPieces[$qtyPiecesCount - 1]; //get the last value in the array, count minus 1 because we start counting from 0

$\u product->getBunlde\u qty()实际上是双倍还是浮动?还是仅仅是一根绳子?在这种情况下,您可以使用:

$qty = round(floatval($_product->getBundle_qty()));
编辑: 现在,如果你想把cm/dm放在字符串后面,我们可以将字符串在所有空格处分解,从而从字符串中创建一个数组。此数组中的最后一个值将是“cm”或“dm”文本

$qtyPieces = explode(" ", $_product->getBundle_qty()); //explode at the space
$qtyPiecesCount = count($qtyPieces); //count all pieces
$qty = round(floatval($_product->getBundle_qty())) . " " . $qtyPieces[$qtyPiecesCount - 1]; //get the last value in the array, count minus 1 because we start counting from 0

$\u product->getBunlde\u qty()实际上是双倍还是浮动?还是仅仅是一根绳子?在这种情况下,您可以使用:

$qty = round(floatval($_product->getBundle_qty()));
编辑: 现在,如果你想把cm/dm放在字符串后面,我们可以将字符串在所有空格处分解,从而从字符串中创建一个数组。此数组中的最后一个值将是“cm”或“dm”文本

$qtyPieces = explode(" ", $_product->getBundle_qty()); //explode at the space
$qtyPiecesCount = count($qtyPieces); //count all pieces
$qty = round(floatval($_product->getBundle_qty())) . " " . $qtyPieces[$qtyPiecesCount - 1]; //get the last value in the array, count minus 1 because we start counting from 0

$\u product->getBunlde\u qty()实际上是双倍还是浮动?还是仅仅是一根绳子?在这种情况下,您可以使用:

$qty = round(floatval($_product->getBundle_qty()));
编辑: 现在,如果你想把cm/dm放在字符串后面,我们可以将字符串在所有空格处分解,从而从字符串中创建一个数组。此数组中的最后一个值将是“cm”或“dm”文本

$qtyPieces = explode(" ", $_product->getBundle_qty()); //explode at the space
$qtyPiecesCount = count($qtyPieces); //count all pieces
$qty = round(floatval($_product->getBundle_qty())) . " " . $qtyPieces[$qtyPiecesCount - 1]; //get the last value in the array, count minus 1 because we start counting from 0

这是因为属性部分是字符串

  • 首先对整数进行四舍五入

     //example:
     $qty = round(2.4);
    
  • 然后将string属性添加回它

     $value = $qty . "cm";
    

  • 这是因为属性部分是字符串

  • 首先对整数进行四舍五入

     //example:
     $qty = round(2.4);
    
  • 然后将string属性添加回它

     $value = $qty . "cm";
    

  • 这是因为属性部分是字符串

  • 首先对整数进行四舍五入

     //example:
     $qty = round(2.4);
    
  • 然后将string属性添加回它

     $value = $qty . "cm";
    

  • 这是因为属性部分是字符串

  • 首先对整数进行四舍五入

     //example:
     $qty = round(2.4);
    
  • 然后将string属性添加回它

     $value = $qty . "cm";
    

  • 使用explode修复了它:

                                $arr = explode(' ',trim($_product->getBundle_qty()));
                                echo $arr[1];
    

    使用explode修复了它:

                                $arr = explode(' ',trim($_product->getBundle_qty()));
                                echo $arr[1];
    

    使用explode修复了它:

                                $arr = explode(' ',trim($_product->getBundle_qty()));
                                echo $arr[1];
    

    使用explode修复了它:

                                $arr = explode(' ',trim($_product->getBundle_qty()));
                                echo $arr[1];
    

    这只是一根绳子。。但使用此代码,他会进行取整,但不会显示属性。。(CM,DM)等等。是的,那是因为要对它进行四舍五入,它需要一个数字。您可以做的是分解字符串以查找空格,获取数组中的最后一项并将其粘贴在舍入的数字后面。让我编辑我的答案来说明我的意思。谢谢你,我自己用explode修复了它!非常感谢。这只是一根绳子。。但使用此代码,他会进行取整,但不会显示属性。。(CM,DM)等等。是的,那是因为要对它进行四舍五入,它需要一个数字。您可以做的是分解字符串以查找空格,获取数组中的最后一项并将其粘贴在舍入的数字后面。让我编辑我的答案来说明我的意思。谢谢你,我自己用explode修复了它!非常感谢。这只是一根绳子。。但使用此代码,他会进行取整,但不会显示属性。。(CM,DM)等等。是的,那是因为要对它进行四舍五入,它需要一个数字。您可以做的是分解字符串以查找空格,获取数组中的最后一项并将其粘贴在舍入的数字后面。让我编辑我的答案来说明我的意思。谢谢你,我自己用explode修复了它!非常感谢。这只是一根绳子。。但使用此代码,他会进行取整,但不会显示属性。。(CM,DM)等等。是的,那是因为要对它进行四舍五入,它需要一个数字。您可以做的是分解字符串以查找空格,获取数组中的最后一项并将其粘贴在舍入的数字后面。让我编辑我的答案来说明我的意思。谢谢你,我自己用explode修复了它!非常感谢。但是CM是一个变量。耶,但是CM是一个变量。耶,但是CM是一个变量。耶,但是CM是一个变量。耶,但是CM是一个变量。