java how to find length of int
int x = 1234;
int lengthOfInt = String.valueOf(x).length(); //convert integer to String
//and get length of the String
java how to find length of int
int x = 1234;
int lengthOfInt = String.valueOf(x).length(); //convert integer to String
//and get length of the String
get number of digits in a number
function getlength(number) {
return number.toString().length;
}
Count the digits in an integer
// Count the digits in an integer
fn numlen(n: u64) -> (u64, usize, usize) {
// Method 1: Calculate
let length1 = ((n as f32).log10()) as usize + 1;
// Method 2: Convert to string
let n_str = n.to_string();
let length2 = n_str.len() as usize;
(n, length1, length2)
}
fn main() {
println!("length n = {:?} ", numlen(123456789));
println!("length n = {:?} ", numlen(1234567891));
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us