1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] TO_CHAR to format decimal places not working for whole numbers

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 3, 2024 às 13:03.

  1. Stack

    Stack Membro Participativo

    I have the below TO_CHAR SQL function in Oracle DB where I simply want to format the number to show as a decimal to 2 decimal places. The below function is what I thought would accomplish that, however as you can see the data being returned back is only displaying the decimal point and not the zeros (since this is a whole number).

    Do I need this wrapped in some conditional function to add the 2 zeros after the decimal place? I only want to do that if it's a whole number, as some values in this column are already are in decimal format. Also the number will be a varying size so I hope the above function accomplishes the varying length the number could be.

    SELECT to_char(B.TRANSACTION_COST,'FM99990.99') TRANSACTION_COST
    ,B.TRANSACTION_COST TRANS_COST_ORIGINAL
    FROM CST_ONHAND_V A,
    CST_ITEM_COST_HISTORY_V B


    Results:

    TRANSACTION_COST TRANS_COST_ORIGINAL
    1800. 1800


    Expected Results:

    1800.00

    Continue reading...

Compartilhe esta Página