InterviewSolution
Saved Bookmarks
| 1. |
Explain iterators in JavaScript? |
|
Answer» The number FORMATTER would allow you to format NUMBERS as the currency you want it to work. The following is an example for US$ currency. Here we have set the currency as ‘USD’: <!DOCTYPE html> <html> <BODY> <p>Average cost of a laptop (US$) </p> <script> var f = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }); document.write(f.format(500)); </script> </body> </html>The output: Let us see another example in Euro. Here we have set the currency as ‘EUR’: <!DOCTYPE html> <html> <body> <p>Average cost of a laptop (US$) </p> <script> var f = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR', minimumFractionDigits: 2, }); document.write(f.format(300)); </script> </body> </html>The output: |
|