MATLAB: How to keep decimal float point only formatMATLAB I could not find any answer about this. So I have a float number (a=323.153), I wanna output look like this with keeping decimal point only: >> a=323. What format shall I use? Thanks. Best Answer If it is just for display you can specify the output format in fprintf.a = 323.153;fprintf('<< a = %.0f.\n',a)output:<< a = 323.Kind regards,Robert Related SolutionsMATLAB: Function to chop a decimal to a variable number of digits You can use an asterisk * to refer to an input of fprintf, so in your case all you need is:fprintf("%.*f\n",x,float);and tested:>> chop(5,4.333352312)4.3334Of course if you want to return that string as an output argument you will need to use sprintf instead:function s = chop(numdigits,float)y = floor(log10(float)+1);x = fix(numdigits - y);s = sprintf("%.*f",x,float);end MATLAB: Converting data to decimal hex2dec(reshape('123446739FBCDE',2,[])') Related QuestionFprintf in if statementHow to use decimal values with fixed point typingHow to format the output using fprintf to show a variable with a user defined amount of decimal places (this amount is stored in a variable)
Best Answer