How do i round to two decimals without zeros at the end

Hi I just want to keed 2 decimal places without those zeros shown at the picture what do I do please I tried round

 Risposta accettata

Jon
Jon il 10 Dic 2020
Modificato: Jon il 10 Dic 2020
I think this might do what you want
fprintf('Dog detected at second %0.2f\n',idx(:))

5 Commenti

Jon
Jon il 10 Dic 2020
Modificato: Jon il 10 Dic 2020
By the way, it is not really clear that you need to do some of the steps in your program. idx is already an integer, so multiplying it by 0.1 will always just give you one digit to the right of the decimal place. So I don't really see the purpose in rounding. Also you can do the scaling in just one line, no need for a loop
idx = idx*0.1
Although the variable name idx is commonly used for indices, this code does not give any evidence that is true here as well. It might be short for 'identifications' instead.
Jon
Jon il 10 Dic 2020
Modificato: Jon il 10 Dic 2020
It looks like idx is assigned by the find function
idx = find(d(:) < 170)
So if I understand your concern, in this case it will definitely return indices. It is only later that the OP changes these into, perhaps some sort of engineering units (second) by multiplying by 0.1, at which point of course they are not indices. My point was that after the original assignment the values of idx are integers, and multiplying an integer by 0.1 only shifts the decimal place by one value, So no point in rounding. To avoid confusion it would be better to assign the new scaled variable to a meaningful name like
tDetected = idx*0.1 % scale results to time in seconds
Ah, yes, I missed that assignment. I thought the variable was not defined in the posted snippet.
I agree i should hava assing it to some meaningfull name.
I multiplay all frames by 0.1 so I get seconds
0.1 is a step is in which window gets shiftted every iteration.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by