Go Down

### Topic: for calculation of of simple multiplication (Read 2812 times)previous topic - next topic

#### irfanatul

##### Mar 15, 2013, 04:50 am
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.

#1
Code?

#### Grumpy_Mike

#2
##### Mar 15, 2013, 01:36 pm
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

#3
##### Mar 15, 2013, 06:01 pm
Try
Code: [Select]
`Serial.print(a,n)`with n being the number of decimals that must be displayed.

#### irfanatul

#4
##### Mar 16, 2013, 08:01 am
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

#5
##### Mar 16, 2013, 10:41 am
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

#6
##### Mar 16, 2013, 11:53 am
thank you sir....
i am getting good result..

#### daphoosa

#7
##### Mar 24, 2013, 02:56 am

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