Prepending single digits with zero.
in
Programming Questions
•
7 months ago
I have no idea how to do this. What I'm doing is constructing a float value based on the time of day in this format: HH.MMSS.
That bit I've worked out. However second(), minute(), and hour(), will return single digits for 0–9. I would like to change that to 00–09.
I've been trying to get java.text.DecimalFormat() to do the trick and it works in some instances but when I combine everything into one float it just drops all the zeros. Here's my example code.
- import java.text.DecimalFormat;
- DecimalFormat df = new java.text.DecimalFormat("00");
- void draw() {
- background(204);
- float s = second();
- float m = minute();
- float h = hour();
- float f = float(df.format(h) + "." + df.format(m) + df.format(s));
- // println(df.format(h)); // WORKS
- // println(df.format(m)); // WORKS
- // println(df.format(s)); // WORKS
- println(df.format(f)); // DOES NOT WORK
- }
Any advice would be fantastic. Thanks all!
Cheers,
Derek.
—
Derek J. Kinsman, creative technologist.
@ghostpressbed
Derek J. Kinsman, creative technologist.
@ghostpressbed
1