• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

Label.caption decimal place (1 Viewer)

Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
hey guys i got a series of labels that do complex calculations, but i want them to round off (or at least display) to 2dp

lblpercentTOTAL = Format(lblpercentTOTAL, "###.##")
lblpercentPOM = Format(lblpercentPOM, "###.##")
lblpercentCMM = Format(lblpercentCMM, "###.##")
lblpercentIC = Format(lblpercentIC, "###.##")
lblpercentSCC = Format(lblpercentSCC, "###.##")
lbltotalcorrecttotal.Caption = Format(lbltotalcorrecttotal, "###.##")

i tried the above but had no luck, any idea's?
 

acmilan

I'll stab ya
Joined
May 24, 2004
Messages
3,989
Location
Jumanji
Gender
Male
HSC
N/A
er wouldnt it be better to use variables to do the calculations rather than labels and then print off the final result on a label?
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
sorry the variables are doing them in another form, all data types are integers
 

steeve

SteeVe
Joined
Sep 10, 2004
Messages
12
Gender
Male
HSC
2005
u can try this

if for example u multiply 2 numbers togehter and u get

lbltest.caption = "104.592344"

u can use the function "Left" syntax being Left( STRING , LENGTH )

lbltest.caption = Left(lbltest.caption, 6)

However this dosent take into account rounding

for rounding u can employ the use of the function "Mid" syntax being Mid( STRING, START, LENGTH)

e.g. MID(lbltest.caption, 7, 1) will return the value of "2" which is he 3rd digit after the DP

Hence u can combine all that


IF MID(lbltest.caption, 7, 1) < 5 THEN
_____lbltest.caption = Left(lbltest.caption, 6)
ELSE
_____lbltest.caption = Left(lbltext.caption, 5)
_____lbltest.caption = lbltest.caption & INT(MID(lbltest.caption, 6, 1) + 1)
ENDIF

remove the _____ thats just indenting

btw the code will give u a runtime error if lbltest.caption is less than 7 digits long or if it has a decimal pt as the 6th digit. u might need to set

IF Len(lbltest.caption) > 7 THEN
_____IF NOT MID(lbltest.caption, 6, 1) = "." THEN
__________Do that thing above
_____ENDIF
ENDIF


hope this is what u wanted
 
Last edited:

aaaman

Banned
Joined
Jan 5, 2005
Messages
851
Location
The Shire
Gender
Male
HSC
2005
Casmira said:
hey guys i got a series of labels that do complex calculations, but i want them to round off (or at least display) to 2dp

lblpercentTOTAL = Format(lblpercentTOTAL, "###.##")
lblpercentPOM = Format(lblpercentPOM, "###.##")
lblpercentCMM = Format(lblpercentCMM, "###.##")
lblpercentIC = Format(lblpercentIC, "###.##")
lblpercentSCC = Format(lblpercentSCC, "###.##")
lbltotalcorrecttotal.Caption = Format(lbltotalcorrecttotal, "###.##")

i tried the above but had no luck, any idea's?
is that 4 da UNSW prog comp :p
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
for my major project, due like on the 16th so i had to someone put in documentation that the percentage value was very accurate( ie. 12 decimal places), impressive :p
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
Casmira said:
hey guys i got a series of labels that do complex calculations, but i want them to round off (or at least display) to 2dp

lblpercentTOTAL = Format(lblpercentTOTAL, "###.##")
lblpercentPOM = Format(lblpercentPOM, "###.##")
lblpercentCMM = Format(lblpercentCMM, "###.##")
lblpercentIC = Format(lblpercentIC, "###.##")
lblpercentSCC = Format(lblpercentSCC, "###.##")
lbltotalcorrecttotal.Caption = Format(lbltotalcorrecttotal, "###.##")

i tried the above but had no luck, any idea's?
Your code is correct and should work in VB. What event are you using to fire this code? I suspect the code is not executing (or maybe the labels are being set after this code has executed).

HTH
Sam
 
Joined
Feb 7, 2005
Messages
665
Location
Sydney
Gender
Male
HSC
2005
SamD said:
Your code is correct and should work in VB. What event are you using to fire this code? I suspect the code is not executing (or maybe the labels are being set after this code has executed).

HTH
Sam
Can you sign my SDD book?
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
SamD said:
Your code is correct and should work in VB. What event are you using to fire this code? I suspect the code is not executing (or maybe the labels are being set after this code has executed).

HTH
Sam
dont worry about it sam, i handed hte project in over 2 weeks ago, it was working just fine, just not how i intended it too, (wanted it to round off 2 decimal place), the event was form_load
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top