# How long is my number?

## Challenge

Given an integer, Q in the range -(2^100) ≤ Q ≤ 2^100, output the number of digits in that number (in base 10).

## Rules

Yes, you may take the number as a string and find its length.

All mathematical functions are allowed.

You may take input in any base, but the output must be the length of the number in base 10.

Do not count the minus sign for negative numbers. The number will never have a decimal point.

Zero can either have one or zero digits.

Assume the input will always be a valid integer.

## Examples

Input > Output

-45 > 2
12548026 > 8
33107638153846291829 > 20
-20000 > 5
0 > 1 or 0


## Winning

Shortest code in bytes wins.

# Excel VBA, 15 Bytes

Anonymous VBE immediate window function that takes input from [A1] and outputs to the VBE immediate window

?[Len(Abs(A1))]


# Fourier, 30 bytes

I~S<0{1}{-2*S~S}S{0}{S^~S}SL^o


Try it on FourIDE!

Fourier doesn't have strings, so it uses logs instead. Bytes are wasted on supporting zero and negative numbers.

# Befunge, 35 bytes

77*~!1+:v
~0#@    ># !#. #- #2_1+


Try it online!

77*~!            add 49 to the stack and see if that is less than 50 (ascii for
'-')
1+:v              if there is a -, don't count it. Add 1 so we don't
have a zero at the top of the stack. Move down.
># !#. #- #2_1+   move right and add one to the total. (Will remove later)
~0#@             Loop back around and take an input and make sure it is not end of
the string (-1, so we make sure it is > 0)
># !#. #- #2_1+   check to see if there was an input. If there was, add one to the
total. If not, move left. Subtract 2 because we added 1 at two
different locations. Print output and end program.


# Bean, 20 bytes

### Hexdump:

00000000: 2650 80d3 d080 a05d 2080 0921 8181 0020  &P.ÓÐ. ] ..!...
00000010: 8001 dc64                                ..Üd


### JavaScript equivalent:

a.match(/\d/g).length;


### Explanation:

Implicitly takes input as a decimal string in a and implicitly outputs the length of the match, which is all the decimal digits in the string. Returns 1 for input of 0.

# Bean, 22 bytes

### Hexdump:

00000000: 2aa0 1f26 4ccc d3a0 8043 53a0 802d 2043  * .&LÌÓ .CS .- C
00000010: 9125 398b 253a                           .%9.%:


### JavaScript equivalent:

with(Math)((log10(abs(A))^0)+1);


### Explanation:

Implicitly takes input as a decimal integer in A, takes the absolute value, then log-base-10, XORs with 0, then adds 1.

When A is 0, the returned value of log10() is -Infinity, and -Infinity ^ 0 is 0 in JavaScript, so the returned value for 0 is 1.

# J, 7 bytes

#@":@**


Try it online!

All the solutions I came up with:

0>.@>.10^.>:@(**)
[:#10&#.inv
#@-.&'-'
#@":@**


The first one is math, the second is base conversion, the third takes a string as input, and the shortest takes a number.

The current solution looks like this:

              ┌─ #
┌─ @ ─┴─ ":
┌─ @ ─┴─ *
──┴─ *


The parent root is a hook between the upper tine and the lower tine. The lower tine (*) is a monad that calculates magnitude. The upper tine is a composition:

         ┌─ #
┌─ @ ─┴─ ":
@ ─┴─ *


This composes the upper tine (another composition) with *, in this case, a dyad. This is the dyad for multiplication. In the last tine:

   ┌─ #
@ ─┴─ ":


This calculates format (":) then length (#).

In English form, this is "multiply x times the sign of x, then convert this to a string, then take the length of this string". Basically, abs.toString.length.

# Perl 5, 9 + 1 = 10 bytes

$_=y/-//c  Try it online! Run with -p (1 byte penalty). ## Explanation $_=y/-//c
{implicit from -p: for each line of input}
y/ //    In {the input}, replace
c     everything except
-        '-'
$_= Store number of replacements back in$_
{implicit from -p: output $_}  We treat the input as a string in order to handle numbers outside the 64-bit range. One interesting trick here is that we don't have to specify what we're replacing the nonhyphens with; we can still count the number of replacements that occur. The TIO link uses -l in order to let us run the program on multiple data without the newlines between them interfering. If the program only has to run once, we can do without it, so long as there's no final newline on the input. # C#, 33 bytes i=>Math.Abs(i).ToString().Length;  • You need to fully qualify Math and you can save bytes by using +"" instead of ToString(). – TheLethalCoder May 17 '17 at 14:51 # MATL, 4 bytes 47>s  Inspired by Martin's Retina answer: count how many characters have code point exceeding 47 (this excludes the minus sign). Try it online! # Braingolf, 2 bytes dl  ### Explaination: dl Implicit input from command-line args to stack d Pop last item from stack, split it into digits, and push each digit to the stack l Push length of stack to the end of the stack Implicit output of last item on stack  # Brain-Flak, 48 + 3 ( -a) = 51 bytes ({}[((((()()()()())){}{})){}{}]){(<><>)}{}([]<>)  Try it online! # REXX 22 Bytes arg "-" a say length(a)  Explanation: There is no distinction in Rexx between numbers and strings. The action you perform is what defines the type. The "typing" applies just to that action and can change at any time. So, here the number (say -20) is treated as a string. The "arg" instruction (short for parse arg) tells Rexx to search for the first "-" and then put everything after it in the variable "a". If "-" is not found then everything goes in "a". Try it here REXX functions and instructions # C#, 28 bytes s=>s.Replace("-","").Length;  # C#, 24 bytes n=>$"{n>0?n:-n}".Length;


# Chaincode, 5 bytes

pqL_+


## Explanation

pqL_+ print(
+   succ(
_      floor(
L        log_10(
pq           abs(
input())))))


# C, 43 bytes

f(char*s){printf("%d",strlen(s)-(*s==45));}


Try it online

# C, 71 38 bytes

• -33 bytes FelipeNardiBatista

Try Online

f(char*t){return*t?(*t>'-')+f(t+1):0;}


# Swift, 138 bytes

You would think there would be an easier way to do this.

import Foundation;var d:(String)->Int={return $0.trimmingCharacters(in:CharacterSet(charactersIn:"0123456789").inverted).characters.count}  You can try it here Un-golfed: import Foundation // Import the Foundation module var d:(String)->Int={ // Create a closure that takes in a String and returns an Int return // Return the following$0.trimmingCharacters(in:  // Removes all characters in the following CharacterSet

CharacterSet(charactersIn:"0123456789").inverted // Create a CharacterSet with all characters that are not digits

).characters.count // Get the length of the resulting String
}


# Axiom, 23 Bytes

f(x)==#(abs(x)::String)


# awk, 22 bytes

$1=length($1<0?-$1:$1)


Try it online!

All test cases

• You can save one byte by using sqrt($1^2) to take the absolute value. TIO. – Chris May 3 '18 at 2:52 # JavaScript, 23 bytes x=>${x<0?-x:x}.length


# Jelly, 5 bytes

A‘l⁵Ċ


Try it online!