View Full Version : Simple math
patrick6
03-19-2004, 01:47 PM
Can someoone plese post the code to take 2 or 3 text boxes. enter numbers into each then add, subtract, multiply, etc and output the results into another text box or paragraph.
Thanks.
Desmond
03-19-2004, 02:44 PM
Hello,
Here's the simplest way i could think of to do this. obviously you'll want to add checks (in case, for example, one input is left blank . . . )
But this example covers the math of what you are trying to do (or at least, what I think you're trying to do!! :) )
Enjoy,
Desmond.
patrick6
03-21-2004, 09:51 AM
That was what I needed. Thanks.
Now if I want to round up everything that is a fraction how would I use that just for the total box?
I looked at the math.ceil function but I was not sure how to implement it using a textbox for result.
your_number = 3.1415;
your_rounded_number = Math.Ceil(your_number);
Say my number is 46.1 and I am going to call it value 6 and display it into Input4
Input.SetText("Input4", value6)
cchian
03-21-2004, 04:57 PM
I am not sure if I understood your question correctly. If you have 46.1 and want to end up with 47, then the following code should do it:
value5 = 46.1
value6 = Math.Ceil(value5);
Input.SetText("Input4", value6);
Corey
03-21-2004, 05:05 PM
cchian just FYI, you should be able to use:
value5 = Math.Ceil(value5);
Or for that matter:
Input.SetText("Input4", Math.Ceil(value5));
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
patrick6
03-21-2004, 05:56 PM
That took care of it.
One last (I hope) problem on this.
If I put a letter instead of a number into the texboxes it gives me an error.
How do I make sure someone only enters numbers instead of letter, etc.?
Patrick
cchian
03-21-2004, 11:55 PM
Do a search for "Masked Input" and you will be able to do exactly what you are asking :)
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.