1

I am trying to get line_total woocommerce price, but i just cant figure out how to deal with number of decimals. It is now showing price with 4 decimals like 5.5444$ and i want it to show max 2 decimals, like 5.54$.

Does anyone know what am i doing wrong? I have no problems with orger_total price which is showing correctly with just 2 decimals.

$myID = 2859;
$myorder = new WC_Order($myID);

    foreach ($myorder->get_items('line_item') as $item) {
        $Data = $Data.OrderLine($item["name"], $item["line_total"], $item["line_tax"], $item["qty"], "piece", "x");
    }

Is there a way to limit $item["line_total"]to max 2 decimal numbers?

2

Just round the decimal to two digit as per your requirement.

$myID = 2859;
$myorder = new WC_Order($myID);

    foreach ($myorder->get_items('line_item') as $item) {
         $rounded_total = round($item["line_total"],2);// allow 2 decimal and avoid further
        $Data = $Data.OrderLine($item["name"], $rounded_total, $item["line_tax"], $item["qty"], "piece", "x");
    }
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.