James Russell Posted December 14, 2011 Share Posted December 14, 2011 Hey all, Database header formula for rounding upwards to the nearest multiple of 5. Ideas? Cheers, J Quote Link to comment
michaelk Posted December 14, 2011 Share Posted December 14, 2011 James Try =(INT(####/5)*5)+5 Example attached. MK 1 1 Quote Link to comment
James Russell Posted December 14, 2011 Author Share Posted December 14, 2011 Michael, Your math logic rocks my layer plane. J Quote Link to comment
James Russell Posted December 14, 2011 Author Share Posted December 14, 2011 Also, INT as a function doesn't seem to agree in one of my current script lines: ABSSTR:=Concat(((INT(3.14/5)*5)+5),'m'); Declaring that INT is not declared as an identifier. Is there an alternative for running in scripts? 3.14 is an example substitute for a much longer formula but the error resultant is the same. J Quote Link to comment
Pat Stanford Posted December 14, 2011 Share Posted December 14, 2011 For Vectorscript use, take a look at Trunc and Round math commands. These function on longints rather than integers though. Quote Link to comment
michaelk Posted December 14, 2011 Share Posted December 14, 2011 If you are scripting I think you have to use Trunc(). (I'm pretty sure it will work on Integer and Long Integer types as well as Real. Or at least I hope it will.) INT isn't a vector script function. I thought there used to be DIV and MOD script functions, but I can't find them in the function reference. hth mk Quote Link to comment
michaelk Posted December 14, 2011 Share Posted December 14, 2011 I think Trunc returns a LONGINT instead of INTEGER. Pat, am I dreaming about DIV and MOD. Weren't those VS functions? mk Quote Link to comment
James Russell Posted December 14, 2011 Author Share Posted December 14, 2011 You've been memorising a fair few functions hey? Worked like a charm. I thought I'd seen Pat do a topic on those a while ago but I could be mistaken. J Quote Link to comment
michaelk Posted December 15, 2011 Share Posted December 15, 2011 Just curious: Did you have to change the VAR type to LONGINT? mk Quote Link to comment
Pat Stanford Posted December 15, 2011 Share Posted December 15, 2011 Pat, am I dreaming about DIV and MOD. Weren't those VS functions? mk Nope, not VS Functions. Arithmetic Operators. Discussed in the VS Language Guide, not in the Function Reference. Obviously I forgot they were there also or I would have mentioned them in my first post. Thanks for jogging my memory. Quote Link to comment
James Russell Posted December 15, 2011 Author Share Posted December 15, 2011 Just left it as an Integer, works quite well. Quote Link to comment
MullinRJ Posted December 15, 2011 Share Posted December 15, 2011 (edited) I should read prior posts more closely before responding. Edited December 15, 2011 by MullinRJ Quote Link to comment
MullinRJ Posted December 15, 2011 Share Posted December 15, 2011 For Vectorscript use, take a look at Trunc and Round math commands. These function on longints rather than integers though. Usually, you can pass an INTEGER where a LONGINT is required. Often, you can do the reverse, but the result can be garbage. Quote Link to comment
James Russell Posted December 15, 2011 Author Share Posted December 15, 2011 I was just doing a whole heap of distance calculations and had never used LONGINTs before now. Used them when I realised that it was levelling out on higher number sets. Is there a low limitation to using LONGINTs more often? What are the advantages/disadvantages? Presumable they are slightly larger data wise which may cause an accumulative slow down in loops... But what else do they do? J Quote Link to comment
Miguel Barrera Posted December 15, 2011 Share Posted December 15, 2011 Integers (short int) have a value range of -32,768 to 32,767 = 16 bits = 2 bytes whereas, Longint (long int) have a range of -2,147,483,648 to 2,147,483,647 = 32 bits = 4 bytes. For most purposes a short integer will be adequate but if the result of an operation is also a short and the value falls outside the limits of the integer, the result will be truncated to the lower/upper limits. This is why Trunc is declared as a LongInt. If the real value is 100,000.736 and it is assigned to a short Integer, the value will be truncated to 32,767 but if it is assigned to a LongInt then it will be 100,000 as expected. Moreover, rgb colors have a range of 0 to 65,535 and are declared as LongInt to hold the upper values but in reality it is an unsigned short integer meaning it does not have negative values. As for DIV and MOD, they are still part of VS but they are operands for integer Division and Remainder. Quote Link to comment
James Russell Posted December 15, 2011 Author Share Posted December 15, 2011 Wow, great details Miguel, thankyou. Quote Link to comment
unearthed Posted December 31, 2020 Share Posted December 31, 2020 On 12/14/2011 at 7:04 PM, michaelk said: James Try =(INT(####/5)*5)+5 Example attached. MK I've been looking for a way to round to nearest 5 for years! Just found this, works very well in worksheets, no more messy small numbers. Happy new year everyone, and especially to michaelk Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.