Round displays 2 decimal points

VEXcode V5 Blocks 1.0.0-2460

print( round( 1.75 ) ) on Brain

This displays “2.00” . How do I get it to print without the decimal point and trailing zeros?

API says: print(const char *format,...) so i assume you can do

float my_var = 1.75;
print("value=%2.2d",my_var);

where %2.2d is “min chars”.“sig digs” and d is decimal (aka float).

2 Likes

The issue you are experiencing is that round still returns a decimal number, so it prints with the zeroes to show the decimal exists.
You can cast a float(decimal number) to an int using int() or static_cast<>, but you still need round() to not truncate the decimal:

print(int(1.75)); //Truncates decimal
print(static_cast<int> (1.75)); //Truncates decimal

print(int(round(1.75))); //Rounds decimal
print(static_cast<int> (round(1.75))); //Rounds decimal

It is preferred to use static_cast over int() because it is safer.

1 Like

Thanks @Owlman and @rpm . I posted this in the VEXcode V5 Blocks forum because I’m working in blocks only. Those options may work in text, but there doesn’t appear to be any type cast or format options in blocks.

look for the “set print precision” block under looks, set to “1”, that should do it.

1 Like