user6534: I am trying to store temperature data in a variable, so that I can use it for making a JSON object, but the problem is, that when I try to store the temperature in a variable, it prints out the wrong value. I'm using a DHT11 temperature/humidity sensor and a library for calculating the temperature.
Serial.print("Temperature (°C): ");
Serial.println((float)DHT11.temperature, DEC);
int temp1 = ((float)DHT11.temperature, DEC);
Serial.println(temp1);

These 4 lines is printing out this:
Temperature (Â°C): 23.0000000000
10

The first one is correct, but the second line should also be saying "23".
I have tried only loading the data in once with the library, as in outcommenting one line, but that does not work.
It's like I have some syntax wrong, but I can't figure out what.

user368: This line:

int temp1 = ((float)DHT11.temperature, DEC);


casts DHT11.temperature to an float, throws away the value, then assigns DEC to temp1. That is not what you want.

int temp1 = DHT11.temperature;



6534: <p>I am trying to store temperature data in a variable, so that I can use it for making a JSON object, but the problem is, that when I try to store the temperature in a variable, it prints out the wrong value. I'm using a DHT11 temperature/humidity sensor and a library for calculating the temperature.</p>

<pre><code>Serial.print("Temperature (°C): ");
Serial.println((float)DHT11.temperature, DEC);
int temp1 = ((float)DHT11.temperature, DEC);
Serial.println(temp1);
</code></pre>

<p>These 4 lines is printing out this:</p>

<pre><code>Temperature (Â°C): 23.0000000000
10
</code></pre>

<p>The first one is correct, but the second line should also be saying "23".
I have tried only loading the data in once with the library, as in outcommenting one line, but that does not work.
It's like I have some syntax wrong, but I can't figure out what.</p>
 368: <p>This line:</p>

<blockquote>
<pre><code>int temp1 = ((float)DHT11.temperature, DEC);
</code></pre>
</blockquote>

<p>casts <code>DHT11.temperature</code> to an <code>float</code>, throws away the value, then assigns <code>DEC</code> to <code>temp1</code>. That is not what you want.</p>

<blockquote>
<pre><code>int temp1 = DHT11.temperature;
</code></pre>
</blockquote>
