This topic is locked
[SOLVED]

NumberFormatter class

12/30/2022 1:48:16 PM
PHPRunner General questions
konenamogo author

Hello

I use the following code in Edit Page - Event : before record is updated and after record was updated

$MontantEnLettre = $values['NetApayerProforma'];
$fmt = new NumberFormatter( 'fr', NumberFormatter::SPELLOUT );
$fmt->format($MontantEnLettre);

$values['MontantEnLettre']=$fmt;

After clicking in Save, i have the following message:
Fatal error: Uncaught Error: Class 'NumberFormatter' not found in C:\xampp\htdocs\StockCom\include\cdeclient_events.php:57 Stack trace: #0 C:\xampp\htdocs\StockCom\classes\editpage.php(1479): eventclass_cdeclient->BeforeEdit(Array, '( idUtilisateur...', Array, Array, '', false, Object(EditPage)) #1 C:\xampp\htdocs\StockCom\classes\editpage.php(1311): EditPage->callBeforeEditEvent() #2 C:\xampp\htdocs\StockCom\classes\editpage.php(280): EditPage->processDataInput() #3 C:\xampp\htdocs\StockCom\cdeclient_edit.php(105): EditPage->process() #4 {main} thrown in C:\xampp\htdocs\StockCom\include\cdeclient_events.php on line 57

how to use the php class 'NumberFormatter' for the conversion of amounts into numbers and display the result in letters in the field $values['MontantEnLettre'] ?

Thanks

Admin 12/30/2022

If you Google Class 'NumberFormatter' not found error message the following page will be a first result.

https://stackoverflow.com/questions/30554177/fatal-error-class-numberformatter-not-found

You are missing PHP extension in php.ini most likely.

konenamogo author 1/2/2023

Hello,
Thank you very much for the very important file php.ini. I uncomment this line
extension = intl
after reading the following link:
https://stackoverflow.com/questions/30554177/fatal-error-class-numberformatter-not-found

global $conn;

$MontantEnLettre = $values['NetApayerProforma'];
$fmt = new NumberFormatter( 'fr', NumberFormatter::SPELLOUT );
$Lettre = $fmt->format($MontantEnLettre);

$sql = "SELECT sum(TotalhHtProf) Total FROM mouvements WHERE CdeClient_IdCdeClient = ".$oldvalues['IdCdeClient'];
$resql = db_query($sql,$conn);
$data = db_fetch_array($resql);

// DEBUT - NKO AU 30-12-2022 CONVERSION DU MONTANT TTC EN LETTRE
$values['MontantEnLettre'] = $Lettre;

the Class 'NumberFormatter' work now. thank you very much and Goog new year 2023

fhumanes 1/2/2023

Hello,

If you want to transform a number into word, you can see my examples in this URL https://fhumanes.com/blog/guias-desarrollo/guia-20-phprunner-transformar-cifras-a-palabras/

Regards,
fernando

konenamogo author 1/3/2023

Hello fhumanes

thank you very much for your examples.

Happy New Year 2023 and thank you for everything.

gretings,
Namogo