Go Down

Topic: for calculation of of simple multiplication (Read 1 time) previous topic - next topic

irfanatul

hi....
i am simple printing the value in double variable.
double a;
a=2.5e-4;
but in serial monitor, it just indicates only zero value.
and i want to use values which in terms of 1e-5 and 1e-6.
i am using arduino due which is 32 bit controller.
so can i use it? and if i am able to use it then where can i see the results.because serial monitor is not able to show these small quantites.

EVP


Grumpy_Mike

Quote
because serial monitor is not able to show these small quantites.

The serial monitor is capable of showing anything you send it.
However if you send it zero it will display zero.
What is wrong is what you are sending it.
Without seeing your code we can only guess what you are doing wrong.

Patouf

Try
Code: [Select]
Serial.print(a,n)with n being the number of decimals that must be displayed.
L.C.

irfanatul

my code is
void setup(){
Serial.begin(115200);
}
void loop(){
double a;
a=1/3333;
Serial.println(a,6);
}
I have written this code but serial monitor indicates 0.000000 but actually it should show 0.0003000.

michinyon

You need to be careful there,   because   1/3333  is literally the division of two integers,  for which the
result will be 0 ( integer )  and then assigned to 0.0 ( double ).

Some computers are smart enough to figure this out maybe,   maybe the Arduino isn't.

I would suggest that you change your code to
Code: [Select]

a = 1.0 / 3333.0 ;


which should ensure a floating point division.     Or just assign  0.0003 to a,  if that is what you want.

Also,  double on the Arduino is going to be a 32 bit standard float,   so there is not much point in using it.
It is the same as the regular float,  not double precision.


irfanatul

thank you sir....
i am getting good result..

daphoosa


...
Also,  double on the Arduino is going to be a 32 bit standard float,   so there is not much point in using it.
It is the same as the regular float,  not double precision.




This is incorrect.  Per the Arduino reference ( http://arduino.cc/en/Reference/Double ), the Arduino Due uses a 64bit float which is double precision.  All of the "standard" 8bit Arduino's do interpret a double as a float.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview