Skip to main content
Added example with trailing zeros.
Source Link

Python, 125 bytes

After deleting my 1st answer (sry!) which could not handle small numbers due to machine epsilon issues, I found a different solution. It handles float as well as integers, trailing zeros (!) and is written as function.

Thanks to @ogaday for the useful hints and for the compact '0'-fix!

Golfed:

def f(x):x+='.';i=x.find('.');z=list(x);del z[i];return'+'.join([str(int(o)*10**(i-j-1))for j,o in enumerate(z)if'0'<o])or'0'

Ungolfed:

def f(x):
  x+='.'
  i=x.find('.')
  z=list(x)
  del z[i]   
  return '+'.join([str(int(o)*10**(i-j-1)) for j,o in enumerate(z) if '0'<o]) or '0'

Usage:

>>> f("0")
'0'

>>> f("32.005")
'30+2+0.005'

>>> f("100020003000009000000.0007")
'100000000000000000000+20000000000000000+3000000000000+9000000+0.0007'

>>> f("1000000000009000000.0007000000000000000002")
'1000000000000000000+9000000+0.0007+2e-22'

>>> f("0001.99")
'1+0.9+0.09'

Python, 125 bytes

After deleting my 1st answer (sry!) which could not handle small numbers due to machine epsilon issues, I found a different solution. It handles float as well as integers, and is written as function.

Thanks to @ogaday for the useful hints and for the compact '0'-fix!

Golfed:

def f(x):x+='.';i=x.find('.');z=list(x);del z[i];return'+'.join([str(int(o)*10**(i-j-1))for j,o in enumerate(z)if'0'<o])or'0'

Ungolfed:

def f(x):
  x+='.'
  i=x.find('.')
  z=list(x)
  del z[i]   
  return '+'.join([str(int(o)*10**(i-j-1)) for j,o in enumerate(z) if '0'<o]) or '0'

Usage:

>>> f("0")
'0'

>>> f("32.005")
'30+2+0.005'

>>> f("100020003000009000000.0007")
'100000000000000000000+20000000000000000+3000000000000+9000000+0.0007'

>>> f("1000000000009000000.0007000000000000000002")
'1000000000000000000+9000000+0.0007+2e-22'

Python, 125 bytes

After deleting my 1st answer (sry!) which could not handle small numbers due to machine epsilon issues, I found a different solution. It handles float as well as integers, trailing zeros (!) and is written as function.

Thanks to @ogaday for the useful hints and for the compact '0'-fix!

Golfed:

def f(x):x+='.';i=x.find('.');z=list(x);del z[i];return'+'.join([str(int(o)*10**(i-j-1))for j,o in enumerate(z)if'0'<o])or'0'

Ungolfed:

def f(x):
  x+='.'
  i=x.find('.')
  z=list(x)
  del z[i]   
  return '+'.join([str(int(o)*10**(i-j-1)) for j,o in enumerate(z) if '0'<o]) or '0'

Usage:

>>> f("0")
'0'

>>> f("32.005")
'30+2+0.005'

>>> f("100020003000009000000.0007")
'100000000000000000000+20000000000000000+3000000000000+9000000+0.0007'

>>> f("1000000000009000000.0007000000000000000002")
'1000000000000000000+9000000+0.0007+2e-22'

>>> f("0001.99")
'1+0.9+0.09'
Added another example.
Source Link

Python, 127125 bytes

After deleting my 1st answer (sry!) which could not handle small numbers due to machine epsilon issues, I found a different solution. It handles float as well as integers, and is written as function.

Thanks to @ogaday for the useful hints and for the compact '0'-fix!

Golfed:

def f(x):z=[c for c in x]+["x+='."];i=z';i=x.indexfind("'."');z=list(x);del z[i];print"+"z[i];return'+'.join([str(int(o)*10**(i-j-1))for j,o in enumerate(z)if o>"0"]if'0'<o])or'0'

Ungolfed:

def f(x):
  z=[c for c in x]+["x+='."]  # The additional dot is needed'
 for integersi=x. find('.')
  i=z.indexz=list("."x)
  del z[i]   
  printreturn "+"'+'.join([str(int(o)*10**(i-j-1)) for j,o in enumerate(z) if o>"0"]'0'<o]) or '0'

Usage:

>>> f("0")
'0'

>>> f("32.009"005")
30+2+0'30+2+0.009005'

>>> f("100020003000009000000.0009"0007")
100000000000000000000+20000000000000000+3000000000000+9000000+0'100000000000000000000+20000000000000000+3000000000000+9000000+0.00090007'

>>> f("1000000000009000000.0007000000000000000002")
'1000000000000000000+9000000+0.0007+2e-22'

Python, 127 bytes

After deleting my 1st answer (sry!) which could not handle small numbers due to machine epsilon issues, I found a different solution. It handles float as well as integers, and is written as function.

Golfed:

def f(x):z=[c for c in x]+["."];i=z.index(".");del z[i];print"+".join([str(int(o)*10**(i-j-1))for j,o in enumerate(z)if o>"0"])

Ungolfed:

def f(x):
  z=[c for c in x]+["."]  # The additional dot is needed for integers. 
  i=z.index(".")
  del z[i]
  print "+".join([str(int(o)*10**(i-j-1)) for j,o in enumerate(z) if o>"0"])

Usage:

>>> f("32.009")
30+2+0.009

>>> f("100020003000009000000.0009")
100000000000000000000+20000000000000000+3000000000000+9000000+0.0009

Python, 125 bytes

After deleting my 1st answer (sry!) which could not handle small numbers due to machine epsilon issues, I found a different solution. It handles float as well as integers, and is written as function.

Thanks to @ogaday for the useful hints and for the compact '0'-fix!

Golfed:

def f(x):x+='.';i=x.find('.');z=list(x);del z[i];return'+'.join([str(int(o)*10**(i-j-1))for j,o in enumerate(z)if'0'<o])or'0'

Ungolfed:

def f(x):
  x+='.'
  i=x.find('.')
  z=list(x)
  del z[i]   
  return '+'.join([str(int(o)*10**(i-j-1)) for j,o in enumerate(z) if '0'<o]) or '0'

Usage:

>>> f("0")
'0'

>>> f("32.005")
'30+2+0.005'

>>> f("100020003000009000000.0007")
'100000000000000000000+20000000000000000+3000000000000+9000000+0.0007'

>>> f("1000000000009000000.0007000000000000000002")
'1000000000000000000+9000000+0.0007+2e-22'
now it handles also integers.
Source Link

Python, 121127 bytes

After deleting my 1st answer (sry!) which could not handle small numbers due to machine epsilon issues, I found a different solution. It handles float as well as integers, and is written as function.

Golfed:

def f(x):z=[c for c in x];i=zx]+["."];i=z.index(".");del z[i];print"+".join([str(int(o)*10**(i-j-1))for j,o in enumerate(z)if o>"0"])

Ungolfed:

def f(x):
  z=[c for c in x]x]+["."]  # The additional dot is needed for integers. 
  i=z.index(".")
  del z[i]
  print "+".join([str(int(o)*10**(i-j-1)) for j,o in enumerate(z) if o>"0"])

Usage:

>>> f("32.009")
30+2+0.009

>>> f("100020003000009000000.0009")
100000000000000000000+20000000000000000+3000000000000+9000000+0.0009

Python, 121 bytes

After deleting my 1st answer (sry!) which could not handle small numbers due to machine epsilon issues, I found a different solution.

Golfed:

def f(x):z=[c for c in x];i=z.index(".");del z[i];print"+".join([str(int(o)*10**(i-j-1))for j,o in enumerate(z)if o>"0"])

Ungolfed:

def f(x):
  z=[c for c in x]
  i=z.index(".")
  del z[i]
  print "+".join([str(int(o)*10**(i-j-1)) for j,o in enumerate(z) if o>"0"])

Usage:

>>> f("32.009")
30+2+0.009

>>> f("100020003000009000000.0009")
100000000000000000000+20000000000000000+3000000000000+9000000+0.0009

Python, 127 bytes

After deleting my 1st answer (sry!) which could not handle small numbers due to machine epsilon issues, I found a different solution. It handles float as well as integers, and is written as function.

Golfed:

def f(x):z=[c for c in x]+["."];i=z.index(".");del z[i];print"+".join([str(int(o)*10**(i-j-1))for j,o in enumerate(z)if o>"0"])

Ungolfed:

def f(x):
  z=[c for c in x]+["."]  # The additional dot is needed for integers. 
  i=z.index(".")
  del z[i]
  print "+".join([str(int(o)*10**(i-j-1)) for j,o in enumerate(z) if o>"0"])

Usage:

>>> f("32.009")
30+2+0.009

>>> f("100020003000009000000.0009")
100000000000000000000+20000000000000000+3000000000000+9000000+0.0009
Removed some unnecessary spaces in golfed version.
Source Link
Loading
added example
Source Link
Loading
Source Link
Loading