Tag Info

New answers tagged

0

f = With[{p = Length[IntegerDigits@#2]}, N[#1 + (2 UnitStep[#1] - 1) #2 10^(-p)]] &; g = f @@@ Partition[#, 2] &; Test case: test = {{0, 1, -2, 259}, {-1, 2, 3, 124}, {-2, 34, -3, 45}, {1, 0, 3, 4}} Grid[{#, "\[RightArrow]", g@#} & /@ test] Now strings would be required to deal with e.g. test2 = {{"-1", "04", "0", "04"}, {"-1", ...


1

Define function f (IntegerLength learn form @belisarius 's answer) f[x_, y_] /; x > 0 := (Abs@x + y/10^(Length@IntegerDigits@y)) // N[#, IntegerLength@y + 1] & f[x_, y_] /; x < 0 := -(Abs@x + y/10^(Length@IntegerDigits@y)) // N[#, IntegerLength@y + 1] & f[x_, y_] /; x == 0 := (Abs@x + y/10^(Length@IntegerDigits@y)) // N[#, IntegerLength@y] ...


6

Similar to Alan's answer but a bit more direct: fix = ToExpression @ ToString @ Row[#, "."] &; in = {0, 1, -2, 259}; fix /@ Partition[in, 2] {0.1, -2.259}


1

ClearAll[f]; f = With[{left = FromDigits /@ IntegerDigits /@ #[[;; ;; 2]], right = N /@ FromDigits /@ ({#, 0} & /@ IntegerDigits /@ #[[2 ;; ;; 2]]), sign = Sign /@ #[[;; ;; 2]] /. 0 -> 1}, sign (left + right)] &; list = {0, 1, -2, 259}; list2 = {0, 1, -2, 259, 3, 141592653}; Grid[{#, f@#} & /@ {list, list2} , Dividers ...


-1

list = {0, 1, -2, 259}; list /. {a_, b_, c_, d_} :> {a.b, If[Sign[c] == -1, -(-c).d, c.d]} (*{0.1, -2.259}*) ToExpression[ StringReplace[ ToString /@ Partition[{0, 1, -2, 259}, 2], {{"{" | "}" | (Whitespace )} :> "", "," -> "."}]] (*{0.1, -2.259}*)


8

May be I'm overthinking this one. list = {0, 1, -2, 259}; f[x_, y_] := x + (2 Boole@NonNegative[x] - 1 ) y/10^IntegerLength[y]//N ; list /. {a_, b_, c_, d_} -> {f[a, b], f[c, d]} (* {0.1, -2.259} *)


3

The first output may look ok but it's not actually a number. See if this does what you want: test = {0, 1, -2, 259} combine[{a_, b_}] := ToExpression[ToString[StringForm["``.``", a, b]]] Map[combine, ArrayReshape[test, {Length[test]/2, 2}]]


2

Try with Export["data_output1.txt", AA, "CSV"]



Top 50 recent answers are included