Number formats in a view

  • I have a number like this

    125113424.265161

    I want it to look like =>

    125,113,424

    OR

    $125,113,424.27

    How to do this ?

  • Isn't this a presentation issue that should be defined on the client, not tying up database server resources?

     

    --------------------
    Colt 45 - the original point and click interface

  • May be so, I was just wondering if one can do this ??

    If so how ?

  • have u tried UDT?

  • Why use a UDT? Are you saying he should create a string representation of numbers that have the required format and store that? That would be a very bad idea, since that means it would no longer be a number and would need other operations to be used as one.

    Digs, you should not care so much how SQL Server stores data. Instead you should focus on presenting the data in the format you require, either by 'transforming' it in a query, or as Phil says do this on the client. After all, normally when a client asks for a number they are really asking for a number, probably because they want to add it to another number (or something). If you give them a string that looks like a number in a certain format they will need to convert that string back into a number to use it as a number.

  • Go to your Tools ---> Options and start playing with those settings.  I have my machine set that way because once I get into the billions of $, I cannot easily see what I am portraying.  Be aware that this affects everything and I now have to do extra coding for integers [ CONVERT( varchar(10), IntegerField) AS IntegerField - you may need to add additional code to show a dollar sign - I have found no need to that].  Plus's and minus's to everything....

    I wasn't born stupid - I had to study.

  • hi cris

    >>May be so, I was just wondering if one can do this ??

    yup,

    but technically when considering work to be done

    >>should focus on presenting the data in the format you require, either by 'transforming' it in a query, or as Phil says do this on the client

  • Ok, if it "MUST" be done in T-SQL then here are a couple of methods to try,

    With decimals

    SELECT CONVERT(varchar(30), CONVERT(money, 1234567.890), 1)

    Without decimals

    SELECT SUBSTRING(CONVERT(varchar(30), CONVERT(money, 1234567.890), 1), 1
    , CHARINDEX('.', CONVERT(varchar(30), CONVERT(money, 1234567.890), 1)) -1)

    Now you can see that something like

    Format$(field, "$#,##0.00")

    is so much simpler

     

    --------------------
    Colt 45 - the original point and click interface

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

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