Two useful things I learned doing homework over the weekend:
USEFUL THING 1: git commit —amend
Lets say that your fingers get ahead of your brain, and that you write your
and then realize that you forgot to add your modified file.
Well, go ahead
and then issue
This will combine the last two commands together, your forgotten file will get linked with the commit message. Problem solved.
USEFUL THING 2: Control significant digits in Ruby
While building our
CashRegister class, I ran into the problem
that Ruby floats return way more digits after the decimal point than you
need to make change.
For example, if you pay for an $8.30 purchase with a $10 bill, you do not expect to get the message:
Your change is $1.6999999999999993
Thanks to a quick HipChat session with classmate Aron, I arrived at the following way to control float output:
Let’s break it down, the key part here is inside the string interpolation:
In particular, the
“%0.2f” is telling
sprintf that you want output to be offset by
0 digits, and include only
.2 digits after the decimal point.
If you want to set the width of your float output, to say right justify,
0 to a larger number,
include padding to make the field 10 digits wide. If you want more or less
precision after the decimal, change the number after the
any number you choose, say
My final output:
Your change is $1.70. Problem solved.
Thanx for reading. Stay tuned for more from the front lines…