lexus2k / ssd1306

Driver for SSD1306, SSD1331, SSD1351, IL9163, ILI9341, ST7735, PCD8544, Nokia 5110 displays running on Arduino/ESP32/Linux (Rasperry) platforms
MIT License
664 stars 127 forks source link

console.println() float problem #113

Closed NuclearPhoenixx closed 4 years ago

NuclearPhoenixx commented 4 years ago

Describe the bug Just encountered this strange behaviour and it seems like the console can print "0.5" as expected but is unable to do so for "1/2". By trying to do so the screen only reads 0.

To Reproduce This is the arduino sketch i tried this with. Uploaded on an ATTiny84a using an SSD1306 128x32 I2C display.

#include <ssd1306.h>
#include <ssd1306_console.h>

Ssd1306Console console;

void setup() {
  /* Replace the line below with the display initialization function, you want to use */
  ssd1306_128x32_i2c_init();
  ssd1306_clearScreen();
  /* Set font to use with console */
  ssd1306_setFixedFont(ssd1306xled_font6x8);

  float a = 1/2;
  float b = 0.5;

  console.clear();
  console.println(a,2);
  console.println(b,2);
}

void loop() {
  //nothing
}

Expected behavior Well... basically it should print 0.5 in both cases I presume.

Please complete the following information:

lexus2k commented 4 years ago

Hi there,

The issue relates basically to your programming language knowledge. The library can do nothing with that.

Try this:

float a = 1f/2f;
NuclearPhoenixx commented 4 years ago

Oops, thank you.