function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andrey BolkonskyAndrey Bolkonsky 

How to get the Length of an Integer?

This is probably a very stupid question but I am very new to this. I cannot find a way to get the length of an integer in the sample below. I thought it would be Amount.length() or Amount.getLength but I keep gettin the error: Method does not exist of incorrect signature. Thanks.

 public String writeNumber(Integer a) {
            a=Amount;
            
            Integer len=Amount.getLength();
}
Best Answer chosen by Andrey Bolkonsky
Malika Pathak 9Malika Pathak 9

Hi Cameron,

getLength() is not a valid function on integer, but you can calculate the length of an integer by converting it to a string.
for example:

 

integer a = 55;
string amount  = string.ValueOf(a);
integer length = amount.Length();
system.debug(length);

If you find this solution is helpful for you please mark the best answer

All Answers

Malika Pathak 9Malika Pathak 9

Hi Cameron,

getLength() is not a valid function on integer, but you can calculate the length of an integer by converting it to a string.
for example:

 

integer a = 55;
string amount  = string.ValueOf(a);
integer length = amount.Length();
system.debug(length);

If you find this solution is helpful for you please mark the best answer
This was selected as the best answer
Andrey BolkonskyAndrey Bolkonsky
Thanks for the help Malika!