- 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.
推薦閱讀
- 黑客攻防從入門到精通(實戰秘笈版)
- UML和模式應用(原書第3版)
- Delphi程序設計基礎:教程、實驗、習題
- WebAssembly實戰
- Python數據分析基礎
- Mastering PHP Design Patterns
- 名師講壇:Spring實戰開發(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- 微信小程序入門指南
- 鴻蒙OS應用編程實戰
- Mastering Concurrency Programming with Java 9(Second Edition)
- Mastering HTML5 Forms
- R的極客理想:量化投資篇
- 軟件測試分析與實踐
- Visual C++開發寶典
- Clojure Web Development Essentials