Numbers
Integers and floats are the most common types in MoonBit.
Int
(32 bit signed integer) can be represented in decimal, hexadecimal, octal, and binary,
and you can use the underscore to separate digits for better readability.
We call these number literals.
The 0xFFFF
is a hexadecimal number, 0o777
is an octal number, 0b1010
is a binary number,
and 1_000_000
is a decimal number equivalent to 1000000
.
fn main {
let dec : Int = 1000000
let dec2 : Int = 1_000_000
let hex : Int = 0xFFFF
let oct = 0o777
let bin = 0b1001
println(1 + 2)
println(1 - 2)
println(1 * 2)
println(5 / 2)
println(10 % 3)
let num1 : Double = 3.14
let num2 : Float = 3.14
}