Module 1 · Mathematical Language and Quantitative Reasoning Lesson 9 of 120
Units, Dimensions, Scale, and Normalization
Cents, currencies, and rates in the same pipeline.
Transcript
23 sentences · select one to jump thereCheck your understanding
Does multiplying all prices by 100 change a simple return?
Code lab
Run it yourself
The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.
/**
* Fintech Math Bootcamp · Lesson 009 of 120
* Units, Dimensions, Scale, and Normalization
* Module 01: Mathematical Language and Quantitative Reasoning
*
* Scenario: Cents, currencies, and rates in the same pipeline
* Rule: 10,000 cents ÷ 100 = 100 currency units
*
* Try it: Does multiplying all prices by 100 change a simple return?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/units-dimensions-scale-and-normalization/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*/
export function lesson009() {
const cents = 10000;
const units = cents / 100;
const ratePerYear = 0.05;
const years = 2;
const interest = units * ratePerYear * years;
const result = {units, interest};
return result;
}
export const checkedResult = {"units":100,"interest":10};
// Run this file directly: npx tsx lessons/01-mathematical-language-and-quantitative-reasoning/009-units-dimensions-scale-and-normalization.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
console.log(JSON.stringify(lesson009(), null, 2));
}
Your output
Press Run to execute the code in your browser.
Expected output
{
"units": 100,
"interest": 10
}"""
Fintech Math Bootcamp · Lesson 009 of 120
Units, Dimensions, Scale, and Normalization
Module 01: Mathematical Language and Quantitative Reasoning
Scenario: Cents, currencies, and rates in the same pipeline
Rule: 10,000 cents ÷ 100 = 100 currency units
Try it: Does multiplying all prices by 100 change a simple return?
Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/units-dimensions-scale-and-normalization/
Free course: https://courses.thefintechbuilder.com
Synthetic teaching example, not financial advice or a production library.
Run it: python main.py
"""
import json
def lesson009() -> dict:
cents = 10000
units = cents / 100
rate_per_year = 0.05
years = 2
interest = units * rate_per_year * years
result = {"units": units, "interest": interest}
return result
if __name__ == "__main__":
print(json.dumps(lesson009(), indent=2))
Your output
Press Run to execute the code in your browser.
Expected output
{
"units": 100,
"interest": 10
}/**
* Fintech Math Bootcamp · Lesson 009 of 120
* Units, Dimensions, Scale, and Normalization
* Module 01: Mathematical Language and Quantitative Reasoning
*
* Scenario: Cents, currencies, and rates in the same pipeline
* Rule: 10,000 cents ÷ 100 = 100 currency units
*
* Try it: Does multiplying all prices by 100 change a simple return?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/units-dimensions-scale-and-normalization/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*
* Run it: javac Main.java && java Main
*/
public class Main {
static final class ConvertedInterest {
final double units;
final double interest;
ConvertedInterest(double units, double interest) {
this.units = units;
this.interest = interest;
}
}
static ConvertedInterest lesson009() {
double cents = 10000;
double units = cents / 100;
double ratePerYear = 0.05;
double years = 2;
double interest = units * ratePerYear * years;
ConvertedInterest result = new ConvertedInterest(units, interest);
return result;
}
public static void main(String[] args) {
ConvertedInterest result = lesson009();
System.out.println(object("units", num(result.units), "interest", num(result.interest)));
}
// Formats a double the way JSON.stringify does: whole numbers without ".0", null for NaN or infinity.
static String num(double x) {
if (Double.isNaN(x) || Double.isInfinite(x)) return "null";
if (x == Math.rint(x) && Math.abs(x) < 1e15) return String.valueOf((long) x);
return String.valueOf(x);
}
static String quote(String text) {
return "\"" + text.replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
}
// Indents an already formatted JSON value by one level.
static String nested(String json) {
return json.replace("\n", "\n ");
}
static String object(String... keysAndValues) {
if (keysAndValues.length == 0) return "{}";
StringBuilder out = new StringBuilder("{");
for (int i = 0; i < keysAndValues.length; i += 2) {
out.append(i == 0 ? "\n " : ",\n ")
.append(quote(keysAndValues[i])).append(": ").append(nested(keysAndValues[i + 1]));
}
return out.append("\n}").toString();
}
}
No browser runner for Java yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
{
"units": 100,
"interest": 10
}// Fintech Math Bootcamp · Lesson 009 of 120
// Units, Dimensions, Scale, and Normalization
// Module 01: Mathematical Language and Quantitative Reasoning
//
// Scenario: Cents, currencies, and rates in the same pipeline
// Rule: 10,000 cents ÷ 100 = 100 currency units
//
// Try it: Does multiplying all prices by 100 change a simple return?
//
// Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/units-dimensions-scale-and-normalization/
// Free course: https://courses.thefintechbuilder.com
// Synthetic teaching example, not financial advice or a production library.
//
// Run it: go run main.go
package main
import (
"encoding/json"
"fmt"
)
type ConvertedInterest struct {
Units float64 `json:"units"`
Interest float64 `json:"interest"`
}
func lesson009() ConvertedInterest {
cents := 10000.0
units := cents / 100
ratePerYear := 0.05
years := 2.0
interest := units * ratePerYear * years
result := ConvertedInterest{Units: units, Interest: interest}
return result
}
func main() {
printJSON(lesson009())
}
// printJSON prints a value as JSON indented with two spaces, like JSON.stringify(value, null, 2).
func printJSON(value any) {
out, err := json.MarshalIndent(value, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(out))
}
No browser runner for Go yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
{
"units": 100,
"interest": 10
}/**
* Fintech Math Bootcamp · Lesson 009 of 120
* Units, Dimensions, Scale, and Normalization
* Module 01: Mathematical Language and Quantitative Reasoning
*
* Scenario: Cents, currencies, and rates in the same pipeline
* Rule: 10,000 cents ÷ 100 = 100 currency units
*
* Try it: Does multiplying all prices by 100 change a simple return?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/units-dimensions-scale-and-normalization/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*
* Run it: g++ -std=c++17 -o main main.cpp && ./main
*/
#include <charconv>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
// Formats a double the way JSON.stringify does: shortest round-trip form, null for NaN or infinity.
std::string num(double x) {
if (!std::isfinite(x)) return "null";
char buffer[32];
auto [end, error] = std::to_chars(buffer, buffer + sizeof buffer, x);
(void)error;
return std::string(buffer, end);
}
std::string quote(const std::string& text) {
std::string out = "\"";
for (char c : text) {
if (c == '"' || c == '\\') out += '\\';
out += c;
}
return out + "\"";
}
// Indents an already formatted JSON value by one level.
std::string nested(const std::string& json) {
std::string out;
for (char c : json) {
out += c;
if (c == '\n') out += " ";
}
return out;
}
std::string object(const std::vector<std::pair<std::string, std::string>>& fields) {
if (fields.empty()) return "{}";
std::string out = "{";
for (std::size_t i = 0; i < fields.size(); ++i) {
out += i == 0 ? "\n " : ",\n ";
out += quote(fields[i].first) + ": " + nested(fields[i].second);
}
return out + "\n}";
}
struct ConvertedInterest {
double units;
double interest;
};
ConvertedInterest lesson009() {
const double cents = 10000;
const double units = cents / 100;
const double ratePerYear = 0.05;
const double years = 2;
const double interest = units * ratePerYear * years;
const ConvertedInterest result{units, interest};
return result;
}
int main() {
const ConvertedInterest result = lesson009();
std::cout << object({{"units", num(result.units)}, {"interest", num(result.interest)}}) << "\n";
}
No browser runner for C++ yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
{
"units": 100,
"interest": 10
}//! Fintech Math Bootcamp · Lesson 009 of 120
//! Units, Dimensions, Scale, and Normalization
//! Module 01: Mathematical Language and Quantitative Reasoning
//!
//! Scenario: Cents, currencies, and rates in the same pipeline
//! Rule: 10,000 cents ÷ 100 = 100 currency units
//!
//! Try it: Does multiplying all prices by 100 change a simple return?
//!
//! Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/units-dimensions-scale-and-normalization/
//! Free course: https://courses.thefintechbuilder.com
//! Synthetic teaching example, not financial advice or a production library.
//!
//! Run it: rustc main.rs && ./main
struct ConvertedInterest {
units: f64,
interest: f64,
}
fn lesson009() -> ConvertedInterest {
let cents = 10000.0;
let units = cents / 100.0;
let rate_per_year = 0.05;
let years = 2.0;
let interest = units * rate_per_year * years;
let result = ConvertedInterest { units, interest };
result
}
fn main() {
let result = lesson009();
println!(
"{}",
object(&[("units", num(result.units)), ("interest", num(result.interest))])
);
}
/// Formats a number the way JSON.stringify does: shortest round-trip form, null for NaN or infinity.
fn num(x: f64) -> String {
if x.is_finite() {
format!("{}", x)
} else {
"null".to_string()
}
}
fn quote(text: &str) -> String {
format!("\"{}\"", text.replace('\\', "\\\\").replace('"', "\\\""))
}
/// Indents an already formatted JSON value by one level.
fn nested(json: &str) -> String {
json.replace('\n', "\n ")
}
fn object(fields: &[(&str, String)]) -> String {
if fields.is_empty() {
return "{}".to_string();
}
let lines: Vec<String> = fields
.iter()
.map(|(key, value)| format!(" {}: {}", quote(key), nested(value)))
.collect();
format!("{{\n{}\n}}", lines.join(",\n"))
}
No browser runner for Rust yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
{
"units": 100,
"interest": 10
}/**
* Fintech Math Bootcamp · Lesson 009 of 120
* Units, Dimensions, Scale, and Normalization
* Module 01: Mathematical Language and Quantitative Reasoning
*
* Scenario: Cents, currencies, and rates in the same pipeline
* Rule: 10,000 cents ÷ 100 = 100 currency units
*
* Try it: Does multiplying all prices by 100 change a simple return?
*
* Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/mathematical-language-and-quantitative-reasoning/units-dimensions-scale-and-normalization/
* Free course: https://courses.thefintechbuilder.com
* Synthetic teaching example, not financial advice or a production library.
*
* Run it: dotnet run (inside a console project that holds this Program.cs)
*/
using System.Text.Json;
var jsonOptions = new JsonSerializerOptions { WriteIndented = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
Console.WriteLine(JsonSerializer.Serialize(Lesson009(), jsonOptions));
static ConvertedInterest Lesson009()
{
const double cents = 10000;
const double units = cents / 100;
const double ratePerYear = 0.05;
const double years = 2;
const double interest = units * ratePerYear * years;
var result = new ConvertedInterest(units, interest);
return result;
}
record ConvertedInterest(double Units, double Interest);
No browser runner for C# yet
Read the code here, then run it in your own toolchain or a ready-made cloud workspace.
Expected output
{
"units": 100,
"interest": 10
}Prefer your own machine? Every file is in the course repository · open it in Codespaces.
Lesson notes
The rule
10,000 cents ÷ 100 = 100 currency units