03Values and kinds
Decimal numbers
Numbers with a fraction part, written with a decimal point.
A decimal number has a fraction part: ၃.၁၄, ၀.၅, -၂.၅. Its kind is
ဒဿမကိန်း ("decimal number"). Other languages call these floating-point numbers, or
floats.
စံကား
Expected output
၃.၁၄
-၂.၅
၁၀.၀
၁၅၀၀.၀
၀.၀၀၁၅
၃.၅
A decimal number prints with a decimal point each time, even when it is a whole number
(၁၀.၀).
Sizes
Like integers, decimal numbers come in sizes. More bits mean more correct digits.
| Kind | Bits | Correct digits (about) |
|---|---|---|
၁၆ ဘစ် ဒဿမကိန်း | 16 | 3 |
၃၂ ဘစ် ဒဿမကိန်း | 32 | 7 |
ဒဿမကိန်း, ၆၄ ဘစ် ဒဿမကိန်း | 64 | 15 (the default) |
၁၂၈ ဘစ် ဒဿမကိန်း | 128 | 33 |
Close, not exact
Decimal numbers are stored in base 2, so most fractions are stored as a close neighbour and not as the true value. Most of the time this goes unnoticed, but now and then the last digits show it:
စံကား
Expected output
၀.၃၀၀၀၀၀၀၀၀၀၀၀၀၀၀၀၄
၀.၀၉၉၉၇၆
This is true of decimal numbers in almost all programming languages, not just Zaka.
Rules
- Decimal numbers are written in base 10 and no other base.
- Scientific notation (
e3,E-3) needs Western digits:1.5e3, not၁.၅e3.
Hands on
- Print
၁ / ၃and then၁.၀ / ၃. What is different? - Print
၃၂ ဘစ် ဒဿမကိန်း ၀.၁. Is it closer to 0.1 than the 16-bit one?
Next: Characters.