Calculating the High and Low of it all - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Calculating the High and Low of it all (/showthread.php?tid=984) Pages:
1
2
|
Calculating the High and Low of it all - Dimster - 10-18-2022 So, I have a massive data base of decimal value with 5 digits after the decimal. I have routine which is trying to find the highest and the lowest of these values. Here is the algorythm that I am using but for some reason it's giving me the Highest value as the Lowest and the Lowest as the Highest. HL = DataBaseValue If HL < 1 And HL < Low Then Low = HL Low = (_Round(Low * 100000)) / 100000 If HL < 1 And HL > High Then High = HL High = (_Round(High * 100000)) / 100000 The rounding is to avoid scientific notation and be sure result will be 5 digit decimal value. I can't see why this algorythm would give the High as Low and the Low as High. RE: Calculating the High and Low of it all - bplus - 10-18-2022 If HL < 1 ??? you only want numbers less than 1? RE: Calculating the High and Low of it all - Pete - 10-18-2022 Try this, instead. Demo Code: (Select All) DataBaseValue$ = "7,3,9,4,2,6,2,8" Pete RE: Calculating the High and Low of it all - Pete - 10-18-2022 The example I posted uses a double loop and swap to rank the database numbers from high to low. It's basically a non-optimized sorting routine. You can put back in the rounding, as needed. Don't let the MID$() stuff confuse you. You don't need it for your program. I put it in the demo as a way to spit out numbers. Just substitute DataBaseValue for DataBaseValue = VAL(MID$()... and you're good to use. Pete RE: Calculating the High and Low of it all - bplus - 10-18-2022 simply start with really low high and really high low , rnd is always < 1 so for example only Code: (Select All) high = -100000 RE: Calculating the High and Low of it all - Pete - 10-18-2022 That's more to the point, as Dim didn't ask for them to be ranked, just pick out the lowest and the highest. If you don't want to seed it, just do... Code: (Select All) FOR i = 1 TO 100 RE: Calculating the High and Low of it all - Dimster - 10-18-2022 Thanks guys, appreciate the help, I'll give them all a try. RE: Calculating the High and Low of it all - Pete - 10-18-2022 If you pick Mark's over mine, no worries. I have no ego invested in this, and besides, my brothers Rocko and Vinnie know where you live. Pete RE: Calculating the High and Low of it all - bplus - 10-18-2022 low = (_Round(low * 100000)) / 100000 BTW this little trick does not work all the time, in fact it fails to return a controlled max number of decimal digits disgustingly often. Code: (Select All) Dim low As Double RE: Calculating the High and Low of it all - Pete - 10-18-2022 Sometimes it's better to be SINGLE... Code: (Select All) $CONSOLE:ONLY Pete |