Join us for
RADAR: AI Edition

pcds (version 0.1.6)

my_round: The function to round to n decimals or to the nearest non-zero decimal place, if rounding to n yields zero.

Description

Returns the rounded number to the n decimals or to the nearest non-zero decimal place, if rounding to n decimals yields zero. The default for n is 2. Function is borrowed from this link.

Usage

my_round(x, n = 2)

Value

The rounded number to n decimals, and if this is zero to the nearest nonzero decimal

Arguments

x

A real number on which rounding will be applied

n

Number of decimal places to round the number. If rounding yields 0, it rounds to the nearest non-zero decimal place.

Author

Elvan Ceyhan

See Also

Examples

Run this code
a=17; b=35

my_round(a/b)
my_round(b/a)

my_round(12.5624)
my_round(-0.64010)
my_round (0.000026)
my_round(-0.00072451)

Run the code above in your browser using DataLab