truncate and floating-points

조회 수: 3 (최근 30일)
Zcarfaz
Zcarfaz 2014년 2월 28일
답변: Roger Stafford 2014년 2월 28일
I need to write a function called truncate that takes a floating-point value as its input and truncates (discards) the value after a specified decimal point before returning the modified floating-point value. It should be possible to call your function from the command window using the following: >> res = truncate(5.672, 2); % results in res = 5.67 >> res = truncate(5.677, 2); % results in res = 5.67 >> res = truncate(-5.672, 2); % results in res = -5.67 >> res = truncate(-5.677, 2); % results in res = -5.67
thanks!

답변 (2개)

Roger Stafford
Roger Stafford 2014년 2월 28일
Yes, it can be "fixed" to accomplish that.

Walter Roberson
Walter Roberson 2014년 2월 28일

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by