[Python] basic rounding mode in Python [duplicate]

Discussão em 'Python' iniciado por Stack, Fevereiro 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have very simple program to calculate some math equations but I can't find the solution I want anywhere on the internet. or may be I don't understand.

    here is my algorithm.

    input the number from the user save it as price. multiply the price with 0.045 and save it as sTax multiply the price with 0.1 and save it as whTax.

    save price + sTax + whTax as Total

    print the Total.

    now what I can't do is to "round_down the sTax to 2 decimals, (1.239 should be 1.23) and round_halfUp whTax to 2 decimal places (1.235 should be 1.24)

    I just want the code for rounding methods I want.

    please help, Thanks

    my question was closed because of the similar wuestions but my question is different, I want two rounding modes one is to round down and other is round HALF_UP .. which whould be similar to java code of BigDecimal bd = new BigDecimal(sTax).setScale(2, RoundingMode.DOWN);

    Continue reading...

Compartilhe esta Página