Results 1 to 2 of 2

Thread: Convert decimal to char

  1. #1
    Join Date
    Mar 2009
    Posts
    32

    Question [Resolved] Convert decimal to char

    Have following:

    Code:
    round((cast(bp.gross_quantity as decimal(10, 2)) / 42), 2) as gross_qty
    which converts gallons to barrels, in this case

    537796 gallons --> 12804.670000

    1. I do not understand why decimals are 6 long when I specified 2

    2. Also need to convert the result (12804.670000) to a char(10) field with implicit 2 decimals embedded like 1280467

    Keep in mind that quantity could be negative as well.

    I tried this:

    Code:
    convert(char(10), round((cast(bp.gross_quantity as decimal(10, 2)) / 42), 2)) as gross_qty
    but it gives overflow error



    Thank you.
    Last edited by snufse; 03-31-2011 at 10:41 AM.

  2. #2
    Join Date
    Mar 2009
    Posts
    32

    Smile

    Got it working this way:

    Code:
    convert(char(10), replace(convert(decimal(10,2), bp.gross_quantity / 42.0), '.', ''))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •