@@ -8,6 +8,15 @@ class NumberConverter
88{
99 public function toWords (int $ number ): string
1010 {
11+ if ($ number >= 1000000000 ) {
12+ $ millions = $ number % 1000000000 ;
13+ if ($ millions === 0 ) {
14+ return $ this ->convertBillions ($ number );
15+ }
16+
17+ return $ this ->toWords ($ millions ) . Dictionary::GLUE_SY ->value . $ this ->convertBillions ($ number - $ millions );
18+ }
19+
1120 if ($ number >= 1000000 ) {
1221 $ hundredThousands = $ number % 1000000 ;
1322 if ($ hundredThousands === 0 ) {
@@ -182,17 +191,49 @@ protected function convertHundredThousands(int $number): string
182191 }
183192
184193 protected function convertMillions (int $ number ): string
194+ {
195+ $ beforeMillions = $ number / 1000000 ;
196+
197+ if ($ beforeMillions >= 1 && $ beforeMillions <= 9 ){
198+ return match ($ number ) {
199+ 1000000 => Dictionary::MILLION ->value ,
200+ 2000000 => Dictionary::TWO_MILLION ->value ,
201+ 3000000 => Dictionary::THREE_MILLION ->value ,
202+ 4000000 => Dictionary::FOUR_MILLION ->value ,
203+ 5000000 => Dictionary::FIVE_MILLION ->value ,
204+ 6000000 => Dictionary::SIX_MILLION ->value ,
205+ 7000000 => Dictionary::SEVEN_MILLION ->value ,
206+ 8000000 => Dictionary::EIGHT_MILLION ->value ,
207+ 9000000 => Dictionary::NINE_MILLION ->value ,
208+ default => '' ,
209+ };
210+ }
211+
212+ if ($ beforeMillions >= 10 && $ beforeMillions <= 99 )
213+ {
214+ return $ this ->toWords ($ beforeMillions ).' tapitrisa ' ;
215+ }
216+
217+ if ($ beforeMillions >= 100 && $ beforeMillions <= 999 )
218+ {
219+ return $ this ->toWords ($ beforeMillions ).' tapitrisa ' ;
220+ }
221+
222+ return '' ;
223+ }
224+
225+ protected function convertBillions (int $ number ): string
185226 {
186227 return match ($ number ) {
187- 1000000 => Dictionary::MILLION ->value ,
188- 2000000 => Dictionary::TWO_MILLION ->value ,
189- 3000000 => Dictionary::THREE_MILLION ->value ,
190- 4000000 => Dictionary::FOUR_MILLION ->value ,
191- 5000000 => Dictionary::FIVE_MILLION ->value ,
192- 6000000 => Dictionary::SIX_MILLION ->value ,
193- 7000000 => Dictionary::SEVEN_MILLION ->value ,
194- 8000000 => Dictionary::EIGHT_MILLION ->value ,
195- 9000000 => Dictionary::NINE_MILLION ->value ,
228+ 1000000000 => Dictionary::BILLION ->value ,
229+ 2000000000 => Dictionary::TWO_BILLION ->value ,
230+ 3000000000 => Dictionary::THREE_BILLION ->value ,
231+ 4000000000 => Dictionary::FOUR_BILLION ->value ,
232+ 5000000000 => Dictionary::FIVE_BILLION ->value ,
233+ 6000000000 => Dictionary::SIX_BILLION ->value ,
234+ 7000000000 => Dictionary::SEVEN_BILLION ->value ,
235+ 8000000000 => Dictionary::EIGHT_BILLION ->value ,
236+ 9000000000 => Dictionary::NINE_BILLION ->value ,
196237 default => '' ,
197238 };
198239 }
0 commit comments