Filter löschen
Filter löschen

Trying to change the amount of decimal points

3 Ansichten (letzte 30 Tage)
Olivia Rose
Olivia Rose am 3 Mär. 2022
Beantwortet: Star Strider am 3 Mär. 2022
This is what I have for the input function
weightArray=[68.6611,8.7929,71.6766,44.1901,76.2861,66.1515,22.6083,36.9491,52.6495,65.6995]
dailyMaterialSum = sum(weightArray,'All')
The output answer is correct, but I need it to only be at 2 decimal points. If I input fprintf('%10.2f \n', dailyMaterialSum) It produces the correct form of the answer, but it isn't considered correct because it's a seperate answer. Where am I supposed to place the fprintf to be correct?
These are the output equations
weightArray = (1 + (100 -1)*(rand (10,1)))'
dailyMaterialSum = MaterialSum(weightArray)

Antworten (1)

Star Strider
Star Strider am 3 Mär. 2022
Probably the easiest is to use the round function:
weightArray=[68.6611,8.7929,71.6766,44.1901,76.2861,66.1515,22.6083,36.9491,52.6495,65.6995]
weightArray = 1×10
68.6611 8.7929 71.6766 44.1901 76.2861 66.1515 22.6083 36.9491 52.6495 65.6995
dailyMaterialSum = sum(weightArray,'All')
dailyMaterialSum = 513.6647
format short g
dailyMaterialSum = round(dailyMaterialSum, 2)
dailyMaterialSum =
513.66
format bank
dailyMaterialSum = round(dailyMaterialSum, 2)
dailyMaterialSum =
513.66
Also format to change the Command Window display.
.

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by