- 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.
推薦閱讀
- Functional Python Programming
- C++案例趣學
- Learning PostgreSQL
- Designing Hyper-V Solutions
- Building a Quadcopter with Arduino
- C#程序設計
- Symfony2 Essentials
- 精通MATLAB(第3版)
- Learning OpenCV 3 Computer Vision with Python(Second Edition)
- ScratchJr趣味編程動手玩:讓孩子用編程講故事
- HTML+CSS+JavaScript編程入門指南(全2冊)
- Raspberry Pi Robotic Blueprints
- Mastering Elixir
- Mastering HTML5 Forms
- 零基礎輕松學C++:青少年趣味編程(全彩版)