Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.3K Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Create a function to concatenate numbers?

Posted 9 years ago

I try to write a function in Mathematica to concat ("join") to numbers. Input (2 & 4) --> 24 Input (-1 & 75) --> -175

At the Moment i work with the following function in Mathematica:

f(a_, b_) := a*10^Floor(1+Log(10, Abs(b)))+Abs(b)

This works fine for:

In:= f(1,13)
Out:=113
In:= f(1,-13)
Out:=113

Doesn't work with:

In:= f(-1,13)
Out:=-87

What I want would be

Out:=-113

A function wich switches the Operator at the end "+b" to "-b" if (a) is negative would help, but i don't know how to achieve this.

POSTED BY: Stephan Kammerer
Posted 9 years ago

Stephan,

I would try it this way:

f[a_, b_] := 
 Module[{tmp}, 
  tmp = Sign[a] FromDigits[
     Join[IntegerDigits[Abs[a]], IntegerDigits[b]]]]
POSTED BY: Michael Helmle
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard