Gadget Renesas

Linking Ideas and Electronics

GR Atelier

Title:Let's try the function on GR-KURUMI, floating point numbers vol.

Displayed Name:@chobichan

Let's try the function on GR-KURUMI, floating point numbers vol.

Concept / Overview
Let's try the function of floating point numbers.
####

Let's try to use floating point numbers

Login in web compiler and generate new project or re-open the project which you just built last time. Let's practice.

Get ready Arduino pro mini for a comparison. Please refer to the code below.

 

void setup()
{
  String s = "float test";
  float f = 9.999f;
  s += f;
  Serial.begin(9600);
  Serial.println(s);
}

 

 

Above code works on Arduino IDE but can’t work for WEB compiler. 

The chart is the execution result on Arduino pro mini.
Found that it’s rounded off to three decimal places.

If two decimal place is effective, seems it’s no problem to show the result of arithmetic operation.

However  someone may seek more accuracy. 
※ Even it doesn’t have practical use.

Please refer to the following code.

 

extern "C"
{
  #include  
}

void setup()
{
  String s = "float test";
  float f = 9.999f;
  char buf[32];
  sprintf(buf,"%f",f);
  s += buf;
  Serial.begin(9600);
  Serial.println(s);
}

 

 

Arduino IDE was not able to deal with %f in sprintf form. Such things usually happen when using simplified printf version. 

WEB compiler can deal with %f. 

The result is shown in the data capture of Tera Term in the chart. On Arduino IDE, when you'd like to control the effective decimal place   in floating point numbers by yourself, use dtostrf.
http://technical.ddo.jp/index.php?dtostrf()

 

 

 

 

 

Renesas MVP infomation @chobichan

General hard engineer,  occasionally writing for technical magazine ...
 

Follow

share