formatting numbers

  • How can i write 13445 as 13,445 and 13444444 as 13,444,444 and 1345 as 1,345.

    Thanks,

    Hari

  • Use the formatting capability of your front-end language.

    --Jonathan



    --Jonathan

  • Well to get exactly what you are looking for will take some extra work.

    But if 123,456.78 is OK try this

    Convert(Char(20), CAST(SUM(Loss_Disb_Amt) AS Money), 1) AS "Loss Disbursement"

    You won't need the inner CAST to money if your field is already defined as Money.

    I think you could "LEFT( above, 17)" to eliminate the decimals.

    KlK, MCSE


    KlK

  • Hi hari,

    hope this solves your problem:

    declare @x money

    set @x = 13445

    select convert(char(10),@x,1)

    Output is: 13,445.00

    quote:


    How can i write 13445 as 13,445 and 13444444 as 13,444,444 and 1345 as 1,345.

    Thanks,

    Hari


  • quote:


    Well to get exactly what you are looking for will take some extra work.

    But if 123,456.78 is OK try this

    Convert(Char(20), CAST(SUM(Loss_Disb_Amt) AS Money), 1) AS "Loss Disbursement"

    You won't need the inner CAST to money if your field is already defined as Money.

    I think you could "LEFT( above, 17)" to eliminate the decimals.

    KlK, MCSE


    Or so you can have a non-specific length try

    LEFT(result, LEN(result) - 3)

    then sub varchar in palce of char and ive a large enough size for the data.

  • I'll stick with Jonathan's suggestion.

    That's job of the client app, not the server.

    Frank

    http://www.insidesql.de

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

  • My front end is Access. If I am displaying the number in a list box I cannot use the formatting capability of Access, I have to use the language suggested by kknudson.

  • You can use an Access query as source for your list box.

    Within the Access Query designer you are able to right-click on your column and choose format. There you should find every format you need.

    Frank

    http://www.insidesql.de

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

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

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