Common Computer Science References
At the end of this lesson, you will be able to:
create the program that has output as currency
"use strict"
variable types:
how to format money, in JS:
document.getElementById('pay').innerHTML = `Your pay will be: $ ${takeHomeSalary.toFixed(2)}`
document.getElementById('pay').innerHTML = 'Your pay will be: $' + takeHomeSalary.toFixed(2)
to allow "decimal" input in your JS
xx = parseFloat(document.getElementById('length-of-rectangle').value)
Option B: use Intl.NumberFormat
const price = 14340;
// Format the price above to CDN using the locale, style, and currency.
let formattedPrice = new Intl.NumberFormat('en-CA', {
style: 'currency',
currency: 'CDN',
});
PHP Option #1: round off to 2 decimal places
echo(round(someVariable, 2));
echo(round(4.96754,2));
PHP Option #2 (most likely not work in debug mode)
in PHP:
$formatAsCurrency = numfmt_create( 'en_EN', NumberFormatter::CURRENCY );
echo num_format_currency($formatAsCurrency, $someVariable, "CDN")."\n";
when dealing with a number that never changes or "almost" never changes, we call that a constant
we use the naming convention of ALL_CAPS
ex: const TAX_RATE = 0.18
create a web page that will do the following:
that calculates the take home pay from a job
we will assume you are in the lower tax bracket and the government will take 18% off your pay!
your pay is the number of hours you worked, times your salary
pay = (hours x rate) x (1.00 - 0.18)
taxes = (hours x rate) x 0.18
see screenshots below: ↓
create the above program in PHP