Multiply float big numbers

Hello
I am new to using Arduino. How can I multiply two big numbers as float? for example,
float A= 2500.0;
float B= 40000000.0;
float G =0.0;
G=A*B
%%%%%%
The result was ovf
thank you

1 Like

Hello! maybe it's better to define the variables you are trying to multiply as double, or maybe even long double.
it should solve the overflow as the numbers you are trying to multiply aren't particularly big.

in second thought a float absolutely should cope with these numbers, so the error is somewhere else.
I don't know if this is the actual code you ran, but it's missing a ';' in the fourth line.

post the complete program (using code tags </>)?

It depends on Arduino used... for Arduino Uno/Nano/Mega a double is synonym of float

1 Like

thank you for help this is the code

float  A=    2500.0;
float  B=  400000000000.0;
float  G =0.0;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  G = A*B;
Serial.print("    ");
  Serial.println(G);
}

Thank you, I use nano arduino

What is a purpose of using this big numbers in your program? Can you decrease it range by changing it units? For example replacing 1000000 mm by 1 km?

this is just an example, I need it the same procedure in my actual code

Please return and edit your code, adding the code tags <\> to it. Respect the forum rules!

What for?

ok sure I am sorry

What is the output?

1 Like

Show the error

1 Like

ovf

It seems like you skiped the reading forum guidelines.

Read the forum guidelines to see how to properly post code and some good information on how to ask the question.
Please do not post again until you read it completely.

AAAAAAA! What a stupid idea to cap the output instead of switching to scientific notation

  if (number > 4294967040.0) return print ("ovf");  // constant determined empirically

Facepalm :man_facepalming:

“empirically” - AAAAAAA!

2 Likes

It was a fix :slight_smile:
Before the library start outputs "ovf", it printed just "0.00" :slight_smile: so "ovf" is definitely better

A fix? It is not a fix but patch to a handicapped implementation of printFloat

1 Like

Hey, folks, perhaps you could explain to @ilafi what they've tripped over, and what the fuss is about?