![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| Hi, I have this variable called strwt it can hold numbers and decimal values IF it holds decimal values like this strwt="134.3" then i want the value in strwt to be strwt="134" But if the decimal value is .6 or .5 then i want the variable to hold strwt="135" But if the strwt value is 132 or the whole number then i want it to stay as it is can someone tell me how i can do this. Todd |
| Sponsored Links |
|
#2
| ||||
| ||||
| I tried using round(strwt) but that seemed to ruond down any .5, so I came up with this little function. Code: function round_no(no)
if instr(cstr(no),".")=0 then
round_no = no
else
Dim arr_no, dec_no
arr_no = split(cstr(no),".")
dec_no = arr_no(ubound(arr_no))
if dec_no <=4 then
round_no = fix(no)
else
round_no = fix(no)+1
end if
end if
end function
Code: round_no(strwt) Hope that helps. |
|
#3
| ||||
| ||||
| @RR - the Round() function allows you to specify how many decimal places to round off to. The syntax is: Round(Number, NumDecimalPlaces) The second argument is optiononal. Just FYI...
__________________ jmurrayhead If you agree with me... click the icon! If my post solved your problem, click the button in the lower right-hand corner of the post.Join our Folding team: DeveloperBarn Folding |
|
#4
| ||||
| ||||
| Quote:
Any idea why it rounds .5 down rather than up? |
|
#5
| ||||
| ||||
| Quote:
Code: Function roundit(number,decPoints)
decPoints = 10^decPoints
roundit = round(number*decPoints+0.1)/decPoints
End Function
|
|
#6
| ||||
| ||||
| It appears that round() conforms to the ISO Standard in that x.5 rounds to an even number.
__________________ Wolffy ------------------------ Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary. |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|