Results 1 to 2 of 2

Thread: MOD arithmetic

  1. #1
    Join Date
    Apr 2004
    Posts
    29

    Unanswered: MOD arithmetic

    Is there a MOD arithmetic function available?
    I need a function to get the next highest rounded number.

  2. #2
    Join Date
    Aug 2004
    Posts
    42
    The MOD operator is %. For example,

    SELECT 100 % 7

    shoud give 2.

    The ceiling function can be used to round up. If you are rounding floating point numbers you may want to introduce some "tolerance". For example,

    create table #f (f float)

    insert #f select 1000
    insert #f select 1001
    insert #f select 1000.0000000000001
    insert #f select 1000.00000000000001

    select str (f, 32, 16) 'Raw Data'
    ,ceiling (f * 0.001) * 1000 'Round up to 1000s'
    ,ceiling (f / 1.000000000000001 * 0.001) * 1000 'Round up to 1000s w/tolerance'
    from #f

    You can use similar logic for rounding down by multiplying by a number just greater than 1.

    This "tolerance" takes care of the situations where you have a floating point number like 2.00000000000001 or 1.9999999999998 or something that you "know" is really. These numbers will show as 2.00 if printed using str() or something but will round to 1 or 3 without the "tolerance" adjustment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •