skip to main
|
skip to sidebar
MATLAB for compbio
Tuesday, June 29, 2010
Truncating or rounding off a decimal value/array to user-specified number of decimal places
Sometimes, you want to truncate long floating point numbers to keep just the first few digits following the decimal point. The easy way to do this is
xr = round(x/n) * n
where
x = original floating point number
n = 10^(-[number of digits after decimal])
e.g. x=1.5673454, n = 0.01 (2 digits after decimal point)
xr = 1.57
1 comment:
Manuel
said...
use round2
rounding PI to 2 decimals:
round2(pi,.01)
April 25, 2012 at 10:13 AM
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
About Me
Anshul
View my complete profile
Blog Archive
►
2011
(1)
►
January
(1)
▼
2010
(5)
►
December
(1)
▼
June
(1)
Truncating or rounding off a decimal value/array t...
►
April
(2)
►
January
(1)
►
2009
(5)
►
October
(1)
►
March
(2)
►
February
(1)
►
January
(1)
►
2008
(2)
►
October
(2)
Labels
append
cluster
code
decimal
error
function
hashtable
high-density
image
k-mer
math
matlab
matlab compiler
mcc
memory
mex
motifs
nohup
plot
python
roc
round
save
scatter
screen
sequence
smoothing
sparse
standalone
surf
unix
Followers
1 comment:
use round2
rounding PI to 2 decimals:
round2(pi,.01)
Post a Comment