You can use the ceil
function to round up a number to the nearest integer or to a specified number of decimal places. To round up 6.2
to one decimal place, you can call the ceil
function as follows:
16 chars2 lines
This multiplies the number by 10, rounds it up to an integer using ceil
, and then divides it back by 10 to get the rounded value.
If you want to round up to two decimal places, you can scale by 100 and then divide by 100.
18 chars2 lines
This will return 6.20
.
gistlibby LogSnag