官术网_书友最值得收藏!

  • Learning Rust
  • Paul Johnson Vesa Kaihlavirta
  • 95字
  • 2021-07-02 23:07:21

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.

主站蜘蛛池模板: 建德市| 上蔡县| 台江县| 青浦区| 黄大仙区| 怀柔区| 平定县| 西昌市| 土默特左旗| 东丰县| 日土县| 吉林省| 尼勒克县| 资兴市| 于田县| 嘉荫县| 个旧市| 疏附县| 永登县| 察哈| 东乌珠穆沁旗| 十堰市| 威远县| 高陵县| 若尔盖县| 泾川县| 桂平市| 牡丹江市| 平乡县| 湘潭市| 德安县| 石嘴山市| 赤水市| 新安县| 西吉县| 微山县| 乳源| 垫江县| 临猗县| 高密市| 昌吉市|