arithmatic function

  • i have two numbers 999 and 888.But I want to muliply them as 900 and 800 .

    Like that i want to do for other numbers

    345*234->300*200

    567*345->500*300.

    Is there any function to achieve this.

    Thanks

  • 
    
    declare @MyNumbers table (a int not null, b int not null)
    insert into @MyNumbers select 345,234
    insert into @MyNumbers select 567,345

    select round(a,-2,0)*round(b,-2,0) from @MyNumbers
  • Sorry; duplicate post. "Delete reply" still nonfunctional.

    Edited by - Jonathan on 11/25/2003 1:44:33 PM



    --Jonathan

  • As you're wanting to truncate rather than round, I think cmore means:

    
    
    SELECT ROUND(1,-2,1)*ROUND(b,-2,1)

    If the vales are an integer data type, you could also just do something like this:

    
    
    SELECT (a/100)*(b/100)*10000

    --Jonathan



    --Jonathan

  • quote:


    As you're wanting to truncate rather than round, I think cmore means:

    
    
    SELECT ROUND(1,-2,1)*ROUND(b,-2,1)

    If the vales are an integer data type, you could also just do something like this:

    
    
    SELECT (a/100)*(b/100)*10000

    --Jonathan


    Oops. Yes thanks for catching that Jonathan.

  • Just curious, why?

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • for two integers @i & @j-2

    the following should work

    ( looks like a slight overkill I know! )

    select POWER(10,FLOOR(LOG10(@i)))*(FLOOR(@i)/POWER(10,FLOOR(LOG10(@i))))

    *

    POWER(10,FLOOR(LOG10(@j)))*(FLOOR(@j)/POWER(10,FLOOR(LOG10(@j))))

    The advantage is that you don't have to worry about the precision of the integers - it'll work for 9 , 99 , 999, 9999 etc.

    Regards

  • Or......

    declare @N int

    declare @m int

    set @N = 86548

    set @m = 21458

    select

    cast(left(@N,1) + replicate(0,len(@N)-1) as int)

    *

    cast(left(@M,1) + replicate(0,len(@M)-1) as int)

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply