Array
(
    [0] => Warning
    [1] => Undefined array key "language"
    [2] => /home/whmcsdev/public_repo/wbteampro.major-release/installation/modules/addons/wbteampro/initialize.php
    [3] => 282
)
Array
(
    [0] => Warning
    [1] => Undefined property: stdClass::$state
    [2] => /home/whmcsdev/public_repo/wbavatax.master/installation/modules/addons/wbavatax/hooks.php
    [3] => 942
)
Array
(
    [0] => Deprecated
    [1] => htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated
    [2] => /home/whmcsdev/public_repo/wbavatax.master/installation/modules/addons/wbavatax/hooks.php
    [3] => 279
)
PHP Decimal Place Handling - Knowledgebase - WHMCS Dev
Dev License: This installation of WHMCS is running under a Development License and is not authorized to be used for production use. Please report any cases of abuse to abuse@whmcs.com

PHP Decimal Place Handling Print

  • 3

The goal here is to show the different method for dealing with decimal places on a floating number.

<?php

// Example
  $float = '100.12345';

// Round
  echo round($float, 2);

// Floor with floor()
  echo floor($float * 100) * 0.01;

// Floor by INT casting
  echo (int)($float * 100) * 0.01;

// Ceiling with ceil()
  echo ceil($float * 100) * 0.01;

// Trim using sprintf()
  echo sprintf("%.2f", $float);

// Trim using number_format()
  echo number_format($float, 2, '', '.');

?>

Was this answer helpful?

« Back

Powered by WHMCompleteSolution