I wrote the following function to approximate a number using chopping arithmetic.
chop(5,4.333352312) function output = chop(numdigits,float)y = floor(log10(float)+1); %number of digits in the integer part
x = fix(numdigits - y); fprintf("%.xf",float) end
The function is meant to approximate a float using numdigits chopping arithmetic. Since that is a variable, the number of digits after the decimal point is unknown. The output in the above example should be 4.3333 but the output is 4e+00. Is there any alternate way to display a variable number of digits after the decimal point?
Best Answer