MATLAB Answers

How to round only two values after decimal point

4 views (last 30 days)
Akshay Math
Akshay Math on 1 Mar 2020
Commented: stozaki on 1 Mar 2020
Hi guys,
I have following block set up and i want 24.02==24.021 but i am getting output as 0 so how can i round the input to consider only two values after decimal point.

  0 Comments

Sign in to comment.

Accepted Answer

Akshay Math
Akshay Math on 1 Mar 2020
First multiply with 100 for two values after decimal then convert into integer and divide by 100.

  0 Comments

Sign in to comment.

More Answers (1)

stozaki
stozaki on 1 Mar 2020
You can use 'round' block and 'subtract' block.

  4 Comments

Show 1 older comment
stozaki
stozaki on 1 Mar 2020
Since you are using the double type for the output of the Constant block, values containing less than a few are output.
If you use a 'data type conversion' block, it will be an integer type.
You can use the round and sabtract blocks to extract fractional values, but why not?
Akshay Math
Akshay Math on 1 Mar 2020
Thanks stozaki, however this worked for me
First multiply with 100 for two values after decimal then convert into integer and divide by 100.
stozaki
stozaki on 1 Mar 2020
@ Akshay
Thank you for trying the data type conversion block. I understand that the location of the binary points was different because you were using a Gain block.
Regards,
stozaki

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!