Specifying the argument types

As with much of the string handling in the C family of languages, it is possible to create a string based on a format string (for example, {0:##.###} would give a formatted output of the form xy.abc).

Similar things can be done in Rust, as follows:

let my_number = format!("{:.3}", 3.1415927); 

In the format string, the colon says we're requesting formatting for the value. Dot and 3 says that we want the number formatted to three decimal points. The formatter rounds the value for us, so the output will be 3.142.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset