0

I need to format (for example 6) to base 3 output (it will be 20). All I found was writing the conversion manually or using another libraries.

let a = (format!("{:b}",n));

or

let a = (format!("{:x}",n));

convert to bin and hex, but I need another base.

PitaJ
  • 12,969
  • 6
  • 36
  • 55
  • Why would Rust put base 3 in the core library? This is a job for a crate. – tadman Feb 09 '23 at 17:46
  • Javascript allows `number.toString(base)` and Rust does have [`from_str_radix`](https://doc.rust-lang.org/stable/std/primitive.i8.html#method.from_str_radix) so I could see why this expectation exists. – PitaJ Feb 09 '23 at 17:53
  • But yeah, I think you'll need to implement this manually. – PitaJ Feb 09 '23 at 18:02
  • half a year ago I was programming in js,so i thought there is something like number.toString(base) :( – MubleBuble Feb 09 '23 at 18:20

0 Answers0