# AMBIGUOUS ERROR????

it really should count in cents…

CURRENT SAVINGS:
0.01 - not really liking .01, if i had to i guess as long as once it hits 100 cents it then becomes \$1.00 and then \$100.00 and then \$1,000.00 and then 1,000,000.00 - not that it will ever but you see the point.

\$1.25, \$1.99 so yeah increment by cents but with the decimal and commas

OK, so another math question.

If I tell you I have 123456 cents, how many dollars do I have? How did you figure that? If I want to write it with a decimal, how do I get the part before and after? What math operations is that?

123456 ___________ = 1234

123456 ___________ = 56

What goes in the blanks?

Don't forget to look here: Arduino Reference - Arduino Reference

Scroll down to Structure.

all i can come up with is FLOAT, divide, subtract, multiply from what i have read.. math was never my forte lol

Ruffsta:
math was never my forte lol

Oh, come on now. We’re talking about third grade math. this isn’t calculus or anything.

What is 123456 / 100 ==

Remember, we’re dealing with integers here (byte, int, long) so there will be no decimals.

Did you look at the page I linked you to? There should be one that’s real obvious for getting the 56.

Oh, come on now. We're talking about third grade math. this isn't calculus or anything.

no kidding lol..

but yes it gives 1,234.56

but how do i get that in here: lcd.print(TotalSaved);

Ruffsta:
but yes it gives 1,234.56

No, it doesn't.

Delta_G:
Remember, we're dealing with integers here (byte, int, long) so there will be no decimals.

Go write a quick test sketch to see if you're not sure.

Ruffsta:
but how do i get that in here: lcd.print(TotalSaved);

``````int dollarPart = totalSaved / 100;
int centPart = WHAT GOES HERE?????;
lcd.print(dollarPart);
lcd.print(".");
lcd.print(centPart);
``````

Have you been looking at the reference page? One of those math operators should just be screaming to get the cents part. What's left over after you do a division?

I noticed earlier that you mentioned float. It would be tempting to use float to handle money, but it isn't a great idea. Floating point numbers have precision and accuracy problems. They're approximations and the math doesn't always come out like you want. Be careful with them. They're only good to 6 or 7 digits of precision and you want to talk about a million. With the cents that's 9 digits.

On top of that they are also slow and they bloat code. Your Arduino can't do floating point calculations. It has to fake it with code. And the code that gets added just to do something simple like 23.45 + 34.56 is grotesque.

So we're going to avoid floats.

Now, enough of that aside, the real question is in the post above this one.

Have you been looking at the reference page? One of those math operators should just be screaming to get the cents part. What's left over after you do a division?

yes and REMAINDER

agreed, floats are not a good idea..

Ruffsta:
yes and REMAINDER

And on that reference page, is there an operator to get just the remainder of a division?

Once we've done this trick to put in a decimal, you should be able to see that the same trick (with different numbers obviously) could be used to put in the commas as well.

divide, multiply and you get a remainder..

Ruffsta:
divide, multiply and you get a remainder..

multiply? Seriously, you don't have to calculate it. Go look at that reference page. It can be done just as easy as the division was.

Horse + water = thirsty horse

I’m amazed the OP is still trying to get his coin counter working...
We gave him all the structures, links and help anyone could want a month ago, but he’s still here banging his head against the books,
All he needs to do is try opening them, and/or try google to find code snippets.

In OP’s defense (despite the attitude), the process is a little involved. Breaking up the number into groups of “3 digits” each is trivial. But, printing them in the proper order with leading zeros and commas in the right places is a little more involved. That part took me another 25 lines of code.

``````void printDollars(uint64_t);

void setup() {
Serial.begin(115200);
delay(2000);

printDollars(1);
printDollars(10);
printDollars(105);
printDollars(158);
printDollars(100204);
printDollars(9112304);
printDollars(91145604);
printDollars(901178957);
printDollars(3071198713);
printDollars(100012345678901525ULL);
printDollars(1000012345678901525ULL);
printDollars(10000012345678901525ULL);
}

void loop() {
}

void printDollars(uint64_t dollars) {
uint8_t cents;
uint16_t thousandsGroups[7];
uint8_t numThousandsGroups = 0;

cents = dollars % 100;
dollars /= 100;
while (dollars > 0) {
thousandsGroups[numThousandsGroups++] = dollars % 1000; // Break up number into "Thousands Groups"
dollars /= 1000;
}
Serial.print("\$");
if (numThousandsGroups == 0) {
Serial.print("0");
} else {
for (int8_t i = numThousandsGroups-1; i >= 0; i--) {    // Reverse the order of the groups
if (i < numThousandsGroups-1) {                       // Don't print leading zeros for left-most group
if (thousandsGroups[i] < 100) {
Serial.print("0");
if (thousandsGroups[i] < 10) {
Serial.print("0");
}
}
}
Serial.print(thousandsGroups[i]);
if (i > 0) {                                          // No comma before the decimal point
Serial.print(",");
}
}
}
Serial.print(".");
if (cents < 10) {
Serial.print("0");
}
Serial.println(cents);
}
``````
``````\$0.01
\$0.10
\$1.05
\$1.58
\$1,002.04
\$91,123.04
\$911,456.04
\$9,011,789.57
\$30,711,987.13
\$1,000,123,456,789,015.25
\$10,000,123,456,789,015.25
\$100,000,123,456,789,015.25
``````