Input, conversion, validation and output
Do not mix responsibilities. Interpret first, calculate second and format last.
Think in four steps: receive raw input, convert it to the working type, validate that it is usable and only then format it for display.
Separating those phases helps you debug much faster when a total or formatted value looks wrong.
Input
Raw value with no trust yet.
- `'19.99'` from an input
- `'1,250.40'` from a legacy API
Conversion
Turn it into the type you really need.
- `String(value)`
- `Number(value)` or `parseFloat(cleaned)`
Validation
Check that the value is usable.
- `Number.isFinite(number)`
- Business range rules
Output
Present it in human format.
- `Intl.NumberFormat` for currency
- Template literals for UI text