float not displaying correctly

Hi!
For my project, I need to make some operations with floats, but the Serial monitor isn't displaying it correctly(((,
here is my code:

float rpm_c = 70;
float rpm_b = 143.3;
float acc = 12;
float capa = 1800;
float aproxtime = 25.71;

void setup()
{
Serial.begin(9600);
Serial.println( (float) (rpm_c/( ( ( (acc*capa) /100) *aproxtime) /capa) ) );
}

Thanks for any help!

What is displayed and what should be displayed ?

UKHeliBob:
What is displayed and what should be displayed ?

yes, sorry, I haven't put that
all of my calculators are displaying 22,688966679631
but arduino says <&&¿¿j

sounds like the BAUD rate in the serial monitor is set to different value to what you have selected in void setup (which is 9600). open the serial monitor and select the BAUD drop down menu to change

liamobsolete:
sounds like the BAUD rate in the serial monitor is set to different value to what you have selected in void setup (which is 9600). open the serial monitor and select the BAUD drop down menu to change

No, it's 9600 BAUD as it is, and more, if after that I display a normal text, it displays correctly

Here is what I get when I run your code

22.69

UKHeliBob:
Here is what I get when I run your code

22.69

Strange, maybe it's something with the version of IDE, or I don't know...
Which's yours?

Which board are you using?

okay i noticed your main expression which is being sent to serial monitor is in void setup

I just put it in void loop and it works fine. I'm getting 22.69

the code looks like this: -
float rpm_c = 70;
float rpm_b = 143.3;
float acc = 12;
float capa = 1800;
float aproxtime = 25.71;

void setup()
{
Serial.begin(9600);
}
void loop(){
Serial.println( (float) (rpm_c/( ( ( (acc*capa) /100) *aproxtime) /capa) ) );
}

liamobsolete:
okay i noticed your main expression which is being sent to serial monitor is in void setup

So?

maybe it's something with the version of IDE

Very unlikely

I am using Windows 10
IDE version 1.8.13
Arduino Nano

Same result using IDE 2.0.0-beta.4

TheMemberFormerlyKnownAsAWOL:
So?

When I try and compile his original code (exactly as it is) I get an error which states undefined reference to loop.
so it does even finish compiling on my ide

and when i run it in void loop it works... albeit as a loop

So, add an empty loop() function like I did

Hi,

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
https://forum.arduino.cc/index.php?topic=712198.0
Then look down to "code problems" about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

Are you using a board with native USB, such as a Leonardo or micro? That will cause Serial to take a noticeable amount of time to establish a connection.

try add this to the top of your setup() code

void setup()
  Serial.begin(9600);
  for (int i = 10; i > 0; i--) {
    Serial.print(' '); Serial.print(i);
    delay(500);
  }
  Serial.println();

If you see the count down you will know that the monitor is connected at the correct board rate

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.