Click here to Skip to main content
15,905,008 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello programmers, first of all i would like thank you all for your big help. Sirs ive got another problem here as you see ive created 5 textboxes where the first four would actually multiply to each other and the solution goes to the fifth textbox. My problem is when it is a whole number (1,2,3,4,etc) the formula is solving it the right way, but if it is a decimal number the the answer is wrong. Please help dont know the syntax.
Here is my code:
VB
If IsNumeric(TextBox1.Text) And IsNumeric(TextBox2.Text) And IsNumeric(TextBox3.Text) AndAlso IsNumeric(TextBox4.Text) Then
          TextBox5.Text = CInt(TextBox1.Text) * CInt(TextBox2.Text) * CInt(TextBox3.Text) * CInt(TextBox4.Text)
      End If
Posted
Comments
chaosgray 17-May-11 21:22pm    
do you try using float?

<br />
TextBox5.Text = CDbl(TextBox1.Text) * CDbl(TextBox2.Text) * CDbl(TextBox3.Text) * CDbl(TextBox4.Text)<br />
<br />
 
Share this answer
 
Comments
janwel 17-May-11 22:08pm    
thanks sir
janwel 17-May-11 22:10pm    
sir is there any way that in can only show two decimal places?
saxenaabhi6 17-May-11 22:22pm    
you can format the string like

TextBox5.Text = Format(TextBox5.Text, "####.##")

that is four place to the right of decimal and 2 to the left

if you want to do the rounding read more about how to round the numbers
janwel 17-May-11 22:40pm    
sir found the solution ^_^ thanks
TextBox5.Text = Round(CDbl(TextBox1.Text) * CDbl(TextBox2.Text) * CDbl(TextBox3.Text) * CDbl(TextBox4.Text),2)
Hi. I've never coded in VB, but I think that maybe you should use CSng instead of CInt.

http://msdn.microsoft.com/en-us/library/s2dy91zy%28v=vs.80%29.aspx[^]
 
Share this answer
 
Comments
saxenaabhi6 17-May-11 22:06pm    
my 5
@janwel, do read the link above
janwel 17-May-11 22:12pm    
sir thats what im looking at the declared variables ^_^ thanks for the post sir( ive tried Cfloat but it doesnt work hehehe)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900