-3

so I have a problem with displaying a double variable in OLED & IR remote calculator, like this (using u8g2):

displayTextOnRight(String(100000, 0)); //ex. of an void and a number

It displays: " " But when I set to ex. 99999 it displays: "99999"

The same is with

displayTextOnRight(String(1000.00, 2)); 

It also displays nothing. (100.00 displays 100.00)

I tried values below zero and it crashes. When I try 6 it's empty whatever I type on my remote.

Please help.

1
  • 1
    What's this "displayTextOnRight()" function? What code are you using? Where did you get it? What is it supposed to do? Commented Aug 16, 2022 at 15:18

1 Answer 1

1

When the first argument to the String constructor is an integer type, it tries to interpret the second argument as a number base and not as a number of decimal places.

So, in String(100000, 0));, it kind of thinks you're asking for the number to represented in the String in base 0 as opposed to decimal (DEC), hexadecimal (HEX), binary (BIN), etc and base 0 isn't a thing.

With a floating point type first argument like 1000.0 the second argument takes on the meaning of decimal places (seen an decimalPlaces in the documentation).

If you want ".00" after an integer number when it's converted to a String it's probably better to just print it in a second .print() call, or to concatenate it to the string. And if you want you can manually type convert integer expressions to floating point type to force selection of the other constructor, e.g. int a = 10000; whatever.print(String(float(a), 2));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.