7
$\begingroup$

Is there a way to concatenate the elements of a list into ONE number?

For example, if there is a list L={13,5,8,0}, then I am looking for a way to append 13, 5, 8 and 0 to produce the result 13580.

$\endgroup$
8
$\begingroup$

You can convert the list numbers to strings, then join and finally convert back to number:

L = {13, 5, 8, 0};

ToExpression[StringJoin[ToString /@ L]]
(* 13580 *)
$\endgroup$
10
$\begingroup$
FromDigits @ StringJoin @ IntegerString @ L

13580

FromDigits @ StringJoin @ IntegerString @ {13, 5, 38, 13}

1353813

$\endgroup$
8
$\begingroup$

Or FromDigits:

FromDigits[{13, 5, 8, 0}]

13580
$\endgroup$
  • 2
    $\begingroup$ (+1) you will need something like FromDigits[Flatten@IntegerDigits@L] to cover cases like L={1, 13, 5, 8, 0}. $\endgroup$ – kglr Jan 19 at 5:33
  • $\begingroup$ @kglr 's comment, and answer, show the proper way to use IntegerDigits. Please see those. $\endgroup$ – Rabbit Jan 19 at 6:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.