Code comment

This commit is contained in:
Laurent Destailleur 2021-03-03 12:05:43 +01:00
parent f11a85a3e3
commit 5f8b52ffc9
2 changed files with 14 additions and 5 deletions

View File

@ -5159,7 +5159,7 @@ function price2num($amount, $rounding = '', $option = 0)
// Convert value to universal number format (no thousand separator, '.' as decimal separator) // Convert value to universal number format (no thousand separator, '.' as decimal separator)
if ($option != 1) { // If not a PHP number or unknown, we change or clean format if ($option != 1) { // If not a PHP number or unknown, we change or clean format
//print 'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'<br>'; //print "\n".'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'<br>';
if (!is_numeric($amount)) { if (!is_numeric($amount)) {
$amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>\_]/', '', $amount); $amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>\_]/', '', $amount);
} }
@ -5188,6 +5188,7 @@ function price2num($amount, $rounding = '', $option = 0)
$amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is . $amount = str_replace($thousand, '', $amount); // Replace of thousand before replace of dec to avoid pb if thousand is .
$amount = str_replace($dec, '.', $amount); $amount = str_replace($dec, '.', $amount);
} }
//print ' XX'.$amount.' '.$rounding;
// Now, make a rounding if required // Now, make a rounding if required
if ($rounding) { if ($rounding) {

View File

@ -108,7 +108,15 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
//$db->begin(); // This is to have all actions inside a transaction even if test launched without suite. //$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
if (! function_exists('mb_substr')) { if (! function_exists('mb_substr')) {
print "\n".__METHOD__." function mb_substr must be enabled.\n"; die(); print "\n".__METHOD__." function mb_substr must be enabled.\n"; die(1);
}
if ($conf->global->MAIN_MAX_DECIMALS_UNIT != 5) {
print "\n".__METHOD__." bad setup for number of digits for unit amount. Must be 5 for this test.\n"; die(1);
}
if ($conf->global->MAIN_MAX_DECIMALS_TOT != 2) {
print "\n".__METHOD__." bad setup for number of digits for unit amount. Must be 2 for this test.\n"; die(1);
} }
print __METHOD__."\n"; print __METHOD__."\n";
@ -1294,7 +1302,7 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
$this->assertEquals(1000.123456, price2num('1 000.123456')); $this->assertEquals(1000.123456, price2num('1 000.123456'));
// Round down // Round down
$this->assertEquals(1000.12, price2num('1 000.123452', 'MT')); $this->assertEquals(1000.12, price2num('1 000.123452', 'MT'), 'Error in round down with MT');
$this->assertEquals(1000.12345, price2num('1 000.123452', 'MU'), "Test MU"); $this->assertEquals(1000.12345, price2num('1 000.123452', 'MU'), "Test MU");
// Round up // Round up