나는 이렇게 학습한다/Algorithm & SQL

1222. Formatting decimal places #0

daco2020 2022. 12. 23. 00:18

Each number should be formatted that it is rounded to two decimal places. You don't need to check whether the input is a valid number because only valid numbers are used in the tests.

Example:    
5.5589 is rounded 5.56   
3.3424 is rounded 3.34



Solution:

def two_decimal_places(n: float) -> float:
    l, r = str(n).split(".")
    r = str(round(int("1"+r[:5]), -3))
    return float(".".join([l, r[1:3]]))
def two_decimal_places(n: float) -> float:
    return round(n, 2)