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

  • 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.

主站蜘蛛池模板: 上虞市| 南郑县| 贵阳市| 政和县| 新巴尔虎左旗| 赣州市| 鄂尔多斯市| 汪清县| 囊谦县| 永嘉县| 墨竹工卡县| 遂平县| 凉山| 沂南县| 连州市| 西藏| 扶沟县| 宝鸡市| 宕昌县| 滦南县| 老河口市| 九龙城区| 成安县| 正镶白旗| 咸丰县| 靖西县| 太原市| 黑龙江省| 临漳县| 四会市| 日土县| 资阳市| 开江县| 长寿区| 陆川县| 城固县| 平南县| 宁乡县| 乌拉特中旗| 涿州市| 麻栗坡县|