How do I get Modulo on:
select 200501 / 4
The sum = 50125.25
I want the .25
I tried:
select 200501 / 4
select CAST((200501 / 4) as float)
select CAST((200501 / 4) as real)
select CAST((200501 / 4) as numeric(16,3))
Also how can one use Modulo(%) with 200501 / 4 ?Modulo returns the remainder, which would be 1 in your case.
Try this. (When I ran your statements I only got a whole number without the
decimal portion.)
declare @.a float, @.b float
select @.a=200501, @.b=4
select @.a/@.b -floor(@.a/@.b)
"marcmc" wrote:
> How do I get Modulo on:
> select 200501 / 4
> The sum = 50125.25
> I want the .25
> I tried:
> select 200501 / 4
> select CAST((200501 / 4) as float)
> select CAST((200501 / 4) as real)
> select CAST((200501 / 4) as numeric(16,3))
> Also how can one use Modulo(%) with 200501 / 4 ?
>|||select (200501 % 4) / convert(money, 4)
> How do I get Modulo on:
> select 200501 / 4
> The sum = 50125.25
> I want the .25
> I tried:
> select 200501 / 4
> select CAST((200501 / 4) as float)
> select CAST((200501 / 4) as real)
> select CAST((200501 / 4) as numeric(16,3))
> Also how can one use Modulo(%) with 200501 / 4 ?
new|||modulo only operates on integer values and returns an integer which is
the remainder, so that's not really what you're looking for here.
the easiest way is to subtract the integer part from the result.
[make sure one of the values is a decimal since you've got two integers]
e.g.
select convert(numeric(16,2), (200501/4.0) - convert(int, (200501/4.0)))
are these for hard-coded numbers or variables/data, integers or numeric?
the actual code will be different depending
marcmc wrote:
> How do I get Modulo on:
> select 200501 / 4
> The sum = 50125.25
> I want the .25
> I tried:
> select 200501 / 4
> select CAST((200501 / 4) as float)
> select CAST((200501 / 4) as real)
> select CAST((200501 / 4) as numeric(16,3))
> Also how can one use Modulo(%) with 200501 / 4 ?
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment