CJam, 3333 26 bytes
r:R,,_fr_ee\'0fe<f{f=R'.f=.+R.e&s~\~t~}{},'+*0e|
This won't work with the Java interpreter; it print floats differently. Try it with the CJam interpreterCJam interpreter.
The last test case prints 9000000+9e-7
, which has been ruled valid by @NinjaBearMonkey.
Thanks to @jimmy23013 for golfing off 7 bytes!
r:R r_ Read a token from STDIN and save itpush ina Rcopy.
,, ee Turn REnumerate (nits characters) into I := [0, ..i. n-1]e.
, push the _array of all
Push a copy[index ofcharacter] Ipairs.
f{ \ } For eachSwap Jthe inoriginal I,input pushon Jtop andof I;the then:stack.
f= '0fe< Perform Mapvectorized comparisonminimum with J overthe Icharacter '0'. This turns J
into 1,This andreplaces all otherdigits elementswith of'0', Ibut intoleaves 0's'.'
R'.f= Map comparisonuntouched, withsince '`.' over< R'0'. This turns the
f{ } For each '.'[index (ifcharacter] present)pair, intopush athe 1pair and all otherthe
string of zeroes charactersand of(possibly) Ra intodot; 0's.then:
\ .+ Swap the Performpair vectorizedon sumtop of the Boolean arraysstack.
~ R.e& Dump Performindex vectorizedand logicalcharacter ANDon withthe Rstack.
t Replace the Thisstring's replaceselement theat non-zerothat integer(s)index with the
correspondingthat character(s) or R.
~ s~ Evaluate Castthe toresulting string and evaluate.
{}, Filter the array to remove zeroes.
'+* Join, using '+' as separator.
0e| If the result is empty, replace it with 0.