CaseyC

12-26-2007, 05:08 PM

I just ran into a problem, that I was finally able to overcome, but the solution was not very elegant.

I have a script that processes input from a HTML form. All of the numeric data is input through text boxes. These values are written to a SQL db where the field definition is "DECIMAL 10,2". I want to use one of these values in a calculation BEFORE I update my db with this value. The problem I run into is this:

I want to multiply one of the input values by a value from another db table (also defined as DECIMAL 10,2). After I retrieve the second value and echo the numbers to the screen they look like this:

'13.30' ------->value that was input through text box before being put in db

2.05 --------->value retrieved from other table for this calculation

attempting to multiply these two values yields a result of '0'.

If I do this multiplication AFTER the inputted value has been written to the db and retrieved again then the echo output to the screen looks like this:

13.30

2.05

and the multiplication yields the correct result.

Falling back on my old Fortran IV days (long, long time ago), this looks like a mixed mode expression, multiplying a string by a numeric variable. Keeping this in mind, I tried several different conversions to try to convert this to decimal, but was never able to come up with the right format. My solution was to just write that input string variable to the db and immediately retrieve it, which yielded the correct format.

After this longwinded introduction, I guess the basic question is:

If my assumption that the input data from the form is a character string is correct, how do I massage it so that it can be used in the multiplication?

Thanks in advance........

I have a script that processes input from a HTML form. All of the numeric data is input through text boxes. These values are written to a SQL db where the field definition is "DECIMAL 10,2". I want to use one of these values in a calculation BEFORE I update my db with this value. The problem I run into is this:

I want to multiply one of the input values by a value from another db table (also defined as DECIMAL 10,2). After I retrieve the second value and echo the numbers to the screen they look like this:

'13.30' ------->value that was input through text box before being put in db

2.05 --------->value retrieved from other table for this calculation

attempting to multiply these two values yields a result of '0'.

If I do this multiplication AFTER the inputted value has been written to the db and retrieved again then the echo output to the screen looks like this:

13.30

2.05

and the multiplication yields the correct result.

Falling back on my old Fortran IV days (long, long time ago), this looks like a mixed mode expression, multiplying a string by a numeric variable. Keeping this in mind, I tried several different conversions to try to convert this to decimal, but was never able to come up with the right format. My solution was to just write that input string variable to the db and immediately retrieve it, which yielded the correct format.

After this longwinded introduction, I guess the basic question is:

If my assumption that the input data from the form is a character string is correct, how do I massage it so that it can be used in the multiplication?

Thanks in advance........