Wednesday, March 7, 2012

Rounding very small negative numbers to string

Hi,
I'm trying to round a very small negative number, e.g. -.024, to a string.
If I round -.024 to 1 place, I get 0.0
However, when converting to string, I get .-0
Is there some combination of functions to get rid of the minus sign in such
a situation, or do I have to put in an IF condition to check if number < .05
and change it to ABS?
Below is code that is resulting in -0.
Thanks.
Alan
DECLARE @.Value float(53)
DECLARE @.ValueRounded float(53)
SET @.Value = -.024 -- Any negative number < .05
SELECT @.Value
SET @.ValueRounded = ROUND(@.Value, 1)
SELECT @.ValueRounded
SELECT CONVERT(CHAR(6), @.ValueRounded)What about this?
DECLARE @.Value float(53)
DECLARE @.ValueRounded decimal(6,1)--convert to decimal
SET @.Value = -.024 -- Any negative number < .05
SELECT @.Value
SET @.ValueRounded = ROUND(@.Value, 1)
SELECT @.ValueRounded
SELECT CONVERT(CHAR(6), @.ValueRounded)
Denis the SQL Menace
http://sqlservercode.blogspot.com/
Alan Z. Scharf wrote:
> Hi,
> I'm trying to round a very small negative number, e.g. -.024, to a string.
> If I round -.024 to 1 place, I get 0.0
> However, when converting to string, I get .-0
> Is there some combination of functions to get rid of the minus sign in suc
h
> a situation, or do I have to put in an IF condition to check if number < .
05
> and change it to ABS?
> Below is code that is resulting in -0.
> Thanks.
> Alan
>
> DECLARE @.Value float(53)
> DECLARE @.ValueRounded float(53)
> SET @.Value = -.024 -- Any negative number < .05
> SELECT @.Value
> SET @.ValueRounded = ROUND(@.Value, 1)
> SELECT @.ValueRounded
> SELECT CONVERT(CHAR(6), @.ValueRounded)|||Menace,
Thanks very much. I figured there must be a way.
Alan
"SQL Menace" <denis.gobo@.gmail.com> wrote in message
news:1149092714.650915.239590@.j55g2000cwa.googlegroups.com...
> What about this?
>
> DECLARE @.Value float(53)
> DECLARE @.ValueRounded decimal(6,1)--convert to decimal
> SET @.Value = -.024 -- Any negative number < .05
> SELECT @.Value
> SET @.ValueRounded = ROUND(@.Value, 1)
> SELECT @.ValueRounded
> SELECT CONVERT(CHAR(6), @.ValueRounded)
>
> Denis the SQL Menace
> http://sqlservercode.blogspot.com/
> Alan Z. Scharf wrote:
string.
such
.05
>|||Is this what u need?
DECLARE @.Value float(53)
SET @.Value = -.025
SELECT ABS(Floor(@.Value))
Regards
Sudarshan Selvaraja
"Alan Z. Scharf" wrote:

> Hi,
> I'm trying to round a very small negative number, e.g. -.024, to a string.
> If I round -.024 to 1 place, I get 0.0
> However, when converting to string, I get .-0
> Is there some combination of functions to get rid of the minus sign in suc
h
> a situation, or do I have to put in an IF condition to check if number < .
05
> and change it to ABS?
> Below is code that is resulting in -0.
> Thanks.
> Alan
>
> DECLARE @.Value float(53)
> DECLARE @.ValueRounded float(53)
> SET @.Value = -.024 -- Any negative number < .05
> SELECT @.Value
> SET @.ValueRounded = ROUND(@.Value, 1)
> SELECT @.ValueRounded
> SELECT CONVERT(CHAR(6), @.ValueRounded)
>
>
>|||BTW, FLOAT is an approximate representation. You would probably be better
off representing your data as a NUMERIC type.
"Alan Z. Scharf" <ascharf@.grapevines.com> wrote in message
news:Od%23oc2MhGHA.3756@.TK2MSFTNGP02.phx.gbl...
> Hi,
> I'm trying to round a very small negative number, e.g. -.024, to a string.
> If I round -.024 to 1 place, I get 0.0
> However, when converting to string, I get .-0
> Is there some combination of functions to get rid of the minus sign in
> such
> a situation, or do I have to put in an IF condition to check if number <
> .05
> and change it to ABS?
> Below is code that is resulting in -0.
> Thanks.
> Alan
>
> DECLARE @.Value float(53)
> DECLARE @.ValueRounded float(53)
> SET @.Value = -.024 -- Any negative number < .05
> SELECT @.Value
> SET @.ValueRounded = ROUND(@.Value, 1)
> SELECT @.ValueRounded
> SELECT CONVERT(CHAR(6), @.ValueRounded)
>
>
>|||>> I'm trying to round a very small negative number, e.g. -.024, to a string
. <<
Why are you formatting data in the back end? The basic principle of a
tiered architecture is that display is done in the front end and never
in the back end. This a more basic programming principle than just SQL
and RDBMS.

No comments:

Post a Comment