• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Helper number does not format decimal

#1
Hello people!

Was there an update to the helper number?
After I updated CI4 to the latest version (4.0.3) it is no longer formatting decimal numbers!

Exemple:


PHP Code:
$number 2.55;
number_to_currency($number'USD'); 


Result:

PHP Code:
US
Reply

#2
I have the same problem. Any solution?

Solved:

number_to_currency($number, 'USD', null, 2);
Reply

#3
number_to_currency($number, 'USD', null, 2); yes that works
Reply

#4
(07-03-2020, 11:54 AM)captain-sensible Wrote: just tried this:

echo number_to_currency(1234.56, 'USD'); 


it returned $1,235

i loaded the helper 'number' in base controller like this:
public function __construct()
{
helper(['text', 'date','uri','html','form','security','number']);


//saves on a lot of typing , or load it in the controller you want to use in controller as :

helper('number');

This way it rounds the decimal places. Thing I needed.

PHP Code:
<?php
function number_to_currency(
    float $num,
    string $currency,
    ?string $locale null,
    ?int $fraction null
): string 

This function receives the $fraction, which we can add the number of decimal places we need. So, resolved.
Reply

#5
yes i posted then read the small text 'solved' so went to delete thread- you must have beaten me to it !
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.