F # Tutorials-numeric processing

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.