MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / thousand_separator

Function thousand_separator

1556-thousand-separator.rs:1–12  ·  view source on GitHub ↗
(n: i32)

Source from the content-addressed store, hash-verified

1pub fn thousand_separator(n: i32) -> String {
2 let s = n.to_string();
3 let mut v: Vec<_> = vec!();
4 for i in 0..s.len()/3 {
5 v.insert(0, &s[s.len()-i*3-3..s.len()-i*3]);
6 }
7 let mo = s.len()%3;
8 if mo != 0 {
9 v.insert(0, &s[..mo]);
10 }
11 v.join(".")
12}
13
14fn main() {
15 let n = 1234;

Callers

nothing calls this directly

Calls 1

insertMethod · 0.80

Tested by

no test coverage detected