Logo

Programming-Idioms

History of Idiom 65 > diff from v7 to v8

Edit summary for version 8 by :

Version 7

2015-08-20, 11:02:49

Version 8

2015-08-20, 12:02:53

Idiom #65 Format decimal number

From real value x in [0,1], create its percentage string representation s with one digit after decimal point. E.g. 0.15625 -> "15.6%"

Idiom #65 Format decimal number

From real value x in [0,1], create its percentage string representation s with one digit after decimal point. E.g. 0.15625 -> "15.6%"

Code
let s = format!("{:.1}%", 100.0*x);
Code
let s = format!("{:.1}%", 100.0 * x);
Demo URL
https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%20%20%20%20let%20x%20%3D%200.15625f64%3B%0A%20%20%20%20let%20s%20%3D%20format!(%22%7B%3A.1%7D%25%22%2C%20100.0%20*%20x)%3B%0A%20%20%20%20%0A%20%20%20%20println!(%22%7B%7D%22%2C%20s)%3B%0A%7D%0A&version=stable