Issues filling rounded numbers into MS Word

1 view (last 30 days)
dweather
dweather on 29 Jan 2020
Answered: Ayush Aniket on 16 Dec 2024
Hello Matlab community!
A baffling one for me here, which should be relatively simple but is not turning out to be.
I'm using report generator to populate a number of Holes in a MS word template with variable values. One is a number containing many sf which I am using the 'round' command to truncate to 1 sf as below
roundedvalue = round(value,1);
append(D, roundedvalue);
However, when I run the script the variable is entered into MS Word still as a 10+sf value:
I guess my questions are:
  1. Is this a Matlab issue or an MS Word issue (I really hope it's a Matlab issue as I don't want to have to drag our my VB knowledge to script it...)
  2. If it is a Matlab issue, how can it be fixed?
Answers gratefully recieved!

Answers (1)

Ayush Aniket
Ayush Aniket on 16 Dec 2024
The issue is due to the way MATLAB handles numeric formatting when appending values to a Word document using the Report Generator. The 'round' function in MATLAB rounds the value to the specified number of decimal places, but when you append this value to a Word document, the default formatting might not reflect the desired precision.
To control the number of significant figures or decimal places when exporting to Word, you can convert the number to a string with the desired format before appending it as shown below:
% Example value
value = 123.456789;
% Round the value to 1 decimal place
roundedValue = round(value, 1);
% Convert the rounded value to a string with 1 decimal place
formattedValue = sprintf('%.1f', roundedValue);
% Do further processing
For more information on 'sprintf', please refer to the below link: https://www.mathworks.com/help/matlab/ref/sprintf.html

Categories

Find more on MATLAB Report Generator in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!