On Wednesday, June 23, 2004, at 12:53 PM, Edwards, Waverly wrote: > > Any suggestions on the fastest way to cut a number down to one digit > beyond the decimal point > While it doesn't look like much I think I'm spending too much time > manipulating strings. > > This is the function that I am working with. The current speed comes > in a string. > I need to save the maximum achieved speed but I also need to display > the speed > in a control. > > I figure (guess) if I can cut off to one number beyond the decimal > while the string value is > converted to a number, I can get rid of the lefts and the instr and > another VAL statement. > > Hopefully there are no errors in this function as I just typed it in. > I have no facilities for > cutting and pasting. > > local fn updateSpeed(@speedInKnots as ^str255) > dim as double tempSpeed > tempSpeed = val( speedInKnots.nil$) > theSpeedStr = ( tempSpeed * 1.51 ) > decimalLoc = instr(1,theSpeedStr,".") > long if decimalLoc <> -1 > decimalLoc++ > theSpeedStr = left$(theSpeedStr,decimLoc) > end if > adjustedSpeed = val(theSpeedStr) > if (adjustedSpeed > gMaxSpeed) then gMaxSpeed = adjustedSpeed > end fn > > I'm guessing something like this > > > dim as double myNumberWithFractionalValue > myNumberWithFractionalValue = myNumberWithFractionalValue AND > someMaskValue > > Any thoughts on how I can make this function more efficient. Wave, Here's one solution: local fn updateSpeed(@speedInKnots as ^str255) dim tempSpeed&, adjustedSpeed# tempSpeed = val( speedInKnots.nil$) * 15.1 adjustedSpeed = tempSpeed / 10.0 if (adjustedSpeed > gMaxSpeed) then gMaxSpeed = adjustedSpeed end fn Here are also two generic fns that will quickly truncate or round a number to the decimal places specified. local fn TruncDecimalPlaces#(myNumber#, places%) dim as long myInt, shift shift = 10 ^ places myInt = myNumber# * shift myNumber = myInt end fn = myNumber# / shift local fn RoundDecimalPlaces#(myNumber#, places%) dim as long myInt, shift shift = 10 ^ places end fn = int(myNumber# * shift) / shift e-e =J= a y " -- To unsubscribe, send ANY message to: futurebasic-unsubscribe@...