- 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.
推薦閱讀
- Expert C++
- Java程序設(shè)計(jì)實(shí)戰(zhàn)教程
- 零基礎(chǔ)PHP學(xué)習(xí)筆記
- JavaScript高效圖形編程
- SpringMVC+MyBatis快速開(kāi)發(fā)與項(xiàng)目實(shí)戰(zhàn)
- Docker進(jìn)階與實(shí)戰(zhàn)
- UI智能化與前端智能化:工程技術(shù)、實(shí)現(xiàn)方法與編程思想
- 機(jī)械工程師Python編程:入門(mén)、實(shí)戰(zhàn)與進(jìn)階
- C語(yǔ)言程序設(shè)計(jì)
- 創(chuàng)意UI:Photoshop玩轉(zhuǎn)APP設(shè)計(jì)
- Python 3快速入門(mén)與實(shí)戰(zhàn)
- 寫(xiě)給青少年的人工智能(Python版·微課視頻版)
- Mastering OpenStack
- Cinder:Begin Creative Coding
- JavaScript高級(jí)程序設(shè)計(jì)(第4版)