[Gambas-user] Rounding to 2 decimals

rocko sunblaster5 at ...626...
Fri Jul 27 19:45:58 CEST 2012


On Fri, 2012-07-27 at 02:05 +0200, LeszekK wrote:
> 'Do not use textboxes for mathematical calculations
> 
> Dim prmAmnt As Integer
> Dim totAmnt As Integer
> Dim perAmnt As Single
> 
> prmAmnt = prmBox.value 'valuebox! not textbox
> totAmnt = totBox.value 'valuebox! not textbox
> perAmnt = Round((prmAmnt / totAmnt * 100), 2)
> ValueBox1.Value = perAmnt & "%"
> 
> I not tested the code but it should work.
> 
> 2012/7/27 rocko <sunblaster5 at gmail.com>:
> > Trying to get my result to just 2 decimal places using the 'Round"
> > function but it' not working for me.
> > This code gives a result of 0% ???
> >
> > Code:
> >   Dim prmAmnt As Integer
> >   Dim totAmnt As Integer
> >   Dim perAmnt As Single
> >
> >   prmAmnt = prmBox.Text
> >   totAmnt = totBox.Text
> >   perAmnt = Round((prmAmnt / totAmnt * 100), 2)
> >
> >   TextLabel1.Text = perAmnt & "%"
> >
Ok I change out all the text boxes for value boxes, but
the code still isn't working.
The last value box dosen't seem to be updating with the result.
Using the code:

  Dim prmAmnt As Integer  'the prime/first number
  Dim totAmnt As Integer   'total amount
  Dim perAmnt As Single    'percentage amount
  
  prmAmnt = prmBox.Value    'get amount from the prmBox
  totAmnt = totBox.Value
  perAmnt = Round((prmAmnt / totAmnt * 100), 2)  
  
  ValueBox1.Value = perAmnt & "%"    
> >
> >
> >
> > ------------------------------------------------------------------------------
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's security and
> > threat landscape has changed and how IT managers can respond. Discussions
> > will include endpoint security, mobile security and the latest in malware
> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> 
> 
> 






More information about the User mailing list