Summary: Use Windows PowerShell to easily get the length of a number.
I want to know the length of a number, but when I use the Length property, it comes back as 1.
How can I get the actual length?
First convert the number to a string, and then get the length of the string:
(12345).tostring().length
???? —-> (∞).ToString().Length
@whyNot that is exactly what my code up there does. Convert to string, then gets the length.
hi, another solution: (PS2) > ‘12345’.length
@Ed Looks like @whynot is trying to overflow the system by getting the length of Infinity 🙂 Sean
if you’re doing a lot of these, the string creation may be a bit taxing on memory – i.e. a string will be created for each number simply to get the length and then thrown away – My suggestion is that if you’re doing lots of these you can use: [Math]::Log10(1234)
+ 1