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
(1)
cluster
(1)
code
(2)
decimal
(1)
error
(1)
function
(1)
hashtable
(1)
high-density
(1)
image
(1)
k-mer
(1)
math
(1)
matlab
(1)
matlab compiler
(1)
mcc
(1)
memory
(1)
mex
(1)
motifs
(1)
nohup
(1)
plot
(1)
python
(1)
roc
(1)
round
(1)
save
(1)
scatter
(1)
screen
(1)
sequence
(1)
smoothing
(1)
sparse
(1)
standalone
(2)
surf
(1)
unix
(1)
Followers
1 comment:
use round2
rounding PI to 2 decimals:
round2(pi,.01)
Post a Comment