Pages: [1]   Go Down
Author Topic: for calculation of of simple multiplication  (Read 1047 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
 
Logged

Yorkshire England
Offline Offline
Sr. Member
****
Karma: 2
Posts: 267
Arduino good init
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 509
Posts: 31462
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Online Online
Jr. Member
**
Karma: 0
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try
Code:
Serial.print(a,n)
with n being the number of decimals that must be displayed.
Logged

L.C.

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Edison Member
*
Karma: 28
Posts: 2037
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 1
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

...
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.
Logged

Pages: [1]   Go Up
Jump to: