note 128214 added to class.numberformatter

From: Date: Sun, 12 Feb 2023 18:24:25 +0000
Subject: note 128214 added to class.numberformatter
Groups: php.notes 
Request: Send a blank email to php-notes+get-220170@lists.php.net to get a copy of this message
The NumberFormatter class can be used to convert integer numbers to Roman numerals without a custom function using an array of symbols and associated values: <?php function intToRomanNumeral(int $num) { static $nf = new NumberFormatter('@numbers=roman', NumberFormatter::DECIMAL); return $nf->format($num); } echo intToRomanNumeral(2); // II echo intToRomanNumeral(5); // V echo intToRomanNumeral(10); // X echo intToRomanNumeral(50); // L echo intToRomanNumeral(57); // LVII echo intToRomanNumeral(58); // LVIII echo intToRomanNumeral(100); // C echo intToRomanNumeral(150); // CL echo intToRomanNumeral(1000); // M echo intToRomanNumeral(10000); // ↂ ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 2603:6010:f702:7ad::1001) ---- Manual Page -- https://php.net/manual/en/class.numberformatter.php Edit -- https://main.php.net/note/edit/128214 Del: integrated -- https://main.php.net/note/delete/128214/integrated Del: useless -- https://main.php.net/note/delete/128214/useless Del: bad code -- https://main.php.net/note/delete/128214/bad+code Del: spam -- https://main.php.net/note/delete/128214/spam Del: non-english -- https://main.php.net/note/delete/128214/non-english Del: in docs -- https://main.php.net/note/delete/128214/in+docs Del: other reasons-- https://main.php.net/note/delete/128214 Reject -- https://main.php.net/note/reject/128214 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220170) next »