Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String to Number

Status
Not open for further replies.

commacoma

Technical User
Mar 23, 2011
3
0
0
GB
Hello!

I'm creating a report on stock, and need the figures to accurately total remaining stock after movements.

The database holds the total quantity of stock moved in each transaction, and it's direction of movement (so either in or out).

The direction is a string (either - or +) and quantity a number. I need to combine these and convert to a number so I can run a sum on them, but have not been able to do this so far.

The below puts them in a string, but does anyone know how I can convert these to a number. When I try 'tonumber' I get 'The String is Non Numeric'.

{trans_detail.direction}&{trans_detail.qty-adjust}

Thanks!

 
Just what is the data? And what have you used to convert?

Saying something like
Code:
ToNumber({trans_detail.direction})
should be fine.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 2008 with SQL and Windows XP [yinyang]
 
Thanks for the reply, but I still get the 'The String is Non Numeric' error.

The only data that's held in {trans_detail.direction} is either a - or + sign. I need to add it on to the number in {trans_detail.qty-adjust} in order to make it either a positive or negative figure.

 
YOu could create a formula like this:

if {trans_detail.direction} = "-" then
-{trans_detail.qty-adjust} else
{trans_detail.qty-adjust}

-LB
 
Ah perfect, knew it'd be something simple! :) Thanks!

 
Another solution

I created two formulas


{Plan1_.in/out} is the column with '+' or '-'
{Plan1_.value} is the column with the value


@pos-neg
Shared numberVar value:=0;
WhilePrintingRecords;
If {Plan1_.in/out}=trim("-") then
value:=-1
else
value:=+1

@Final
global numberVar value;
{Plan1_.value}*{@Pos-neg}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top