Home Forums SQL Server 2005 Development How to add "dot" after every three digits in a number in sql 2005 RE: How to add "dot" after every three digits in a number in sql 2005

  • obarahmeh I created a table as:

    CREATE TABLE [dbo].[DTable](

    [Dvalue] [numeric](15, 4) NULL,

    [Comment] [varchar](50) NULL

    ) ON [PRIMARY]

    END

    Entered various values and then used the following T-SQL statement to return the values

    SELECT Dvalue AS 'Original input',

    CASE Dvalue

    WHEN 0 THEN 'oops'

    ELSE REPLACE(CAST(Dvalue AS VARCHAR(25)),'.','')

    END AS 'Decimal point removed',

    ROUND(Dvalue,0,1) AS 'Truncated', ROUND(Dvalue,0) AS 'Rounded', comment

    FROM DTable

    Resulting in:

    Original input Decimal point removedTruncated Rounded Entered as:

    12345678901.000012345678901000012345678901.000012345678901.0000without decimal point

    12345678901.000012345678901000012345678901.000012345678901.0000 With decimal point no fractional part

    12345678901.234512345678901234512345678901.000012345678901.0000 with fractional part

    12345678901.999912345678901999912345678901.000012345678902.0000 with fractional part greater than .5

    46905730295.000046905730295000046905730295.000046905730295.0000obarahmeh shortened value

    46905730295.547046905730295547046905730295.000046905730296.0000Obrahmeh modified value

    How do you want to handle the decimal point and numeirc values to the right of the decimal pont?

    By the way if the column were defined as Numeric(15,0) values entered would be equal to the rounded value displayed above.

    Entering your value of

    46905730295547

    results in the error message

    Arithmetic overflow error converting numeric to data type numeric

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]