This time, we learn the numerical calculation. First, look at the following code:
#light
let x = 10.0 + 12.0 - 3.0
let y = x * 2.0 + 1.0
let r = x/3.0
printfn "x = %g, y = %g, r = %g" x y r
There is little need to explain this code. Because the operation symbol is consistent with C #.
#light
let x = 4 + 6 - 3
let y = x * 2 + 1
let q = x / 3
let r = x % 3
printfn "x = %d, y = %d, q = %d, q = %d" x y q r
The results of the operation are:
x = 7, y =, q = 2, q = 1
The computation between integers, and the result is an integer. This is the same as C #. The code for floating-point operations is as follows:
#light
let x = 10.0 + 12.0 - 3.0
let y = x * 2.0 + 1.0
let r = x/3.0
printfn "x = %g, y = %g, r = %g" x y r
The%g is used in the PRINTFN. %g should C language also have it, a long time ago used now remember is not very clear. The results of the operation are:
x =, y = 6.33333
Where the decimal part is not displayed if it is 0.
But if you use the%f, the small number of chapters show unconditionally.
For the numeric operations of F #, there should be no particular difficulty in using them if you know some other language.