![]() |
【转帖】a little help with rounding
a little help with rounding ?
i have the following code and i as understand it it should round up if decimal = 5 or greater but it does not, if i have a part that has a thickness of .125 it gives back .12 but it should give back .13. does anybody see what could be wrong ? function getthickness(thickness as variant) dim swsheetmetal as sldworks.sheetmetalfeaturedata dim userunits as variant dim convfactor as double set swapp = createobject("sldworks.application") set part = swapp.activedoc userunits = part.getunits() ' debug.print "lengthunit = " & userunits(0) ' debug.print "fraction base = " & userunits(1) ' debug.print "fractiondenominator = " & userunits(2) ' debug.print "significantdigits = " & userunits(3) ' debug.print "roundtofraction = " & userunits(4) select case part.getunits(0) case swmm convfactor = 1 * 1000 case swcm convfactor = 1 * 100 case swmeter convfactor = 1 case swinches convfactor = 1 / 0.0254 case swfeet convfactor = 1 / (0.0254 * 12) case swfeetinches convfactor = 1 / 0.0254 ' pass inches through case swangstrom convfactor = 10000000000# case swnanometer convfactor = 1000000000 case swmicron convfactor = 1000000 case swmil convfactor = (1 / 0.0254) * 1000 case swuin convfactor = (1 / 0.0254) * 1000000 end select set swfeat = part.firstfeature while not swfeat is nothing 'debug.print swfeat.name & " - " & swfeat.gettypename if swfeat.gettypename = "sheetmetal" then set swsheetmetal = swfeat.getdefinition thickness = swsheetmetal.thickness end if set swfeat = swfeat.getnextfeature wend thickness = round(thickness * convfactor, userunits(3)) debug.print (thickness) end function solidworks 2006,2007,2008,2009 (office premium.) core 2 duo e6850 @ 3.00 mhz window xp pro sp3 32 bit ati firegl v7350 ben, could it have to do with the fact that the thickness is a linked dimension (as shown in the equations folder) and it may be defaulted to two decimal places, dropping the decimals after? unfortunately, i don't know what the api call is to change that, but that's my guess. it's probably some kind of setuserpreference, but i haven't found anything. >>wayddaminnit, i just found something else. in the part.getunits function, the fifth parameter, roundtofraction, denotes whether to round something up or not. you may want to setunits and ensure that it is rounding (true) to get the results you want. let me know what you find out! to defeat the wheat, go against the grain. edited: 11/07/2008 at 10:11 am by tom fosler well, technically, .12 is the correct value since on drawings you should round to the nearest even number. it frustrates me that sw does not do this automatically. matt lorono solidworks 2007 sp3.1 cad engineer/ecn analyst hmm.. matt, not sure that i agree with you. is the rule not: 5 you always round up ? solidworks 2006,2007,2008,2009 (office premium.) core 2 duo e6850 @ 3.00 mhz window xp pro sp3 32 bit ati firegl v7350 in normal mathematics, you are normally taught to round up for 5. however, engineering rule of rounding is typically to round to the nearest even number for statistical purposes. see : astm e 29 no luck yet tom. i am possibly not doing it right yet but i will keep trying thanks for the reply. solidworks 2006,2007,2008,2009 (office premium.) core 2 duo e6850 @ 3.00 mhz window xp pro sp3 32 bit ati firegl v7350 quick |
所有的时间均为北京时间。 现在的时间是 08:59 AM. |