Printing leading zeroes
#9
this brings back memories for me, as a "former code monkey" back in my day.

we used to have to format our own strings for display as a regular programming feature, then yeah, you made it into a genericized routine.

I used to let the user save a "format string", then fed that into the pretty printing output. hey, they only have to set the format string ONCE.

format string "3.2" would yield...  000.00
format string "2.0" would yield...  00

later on, naturally a zillion functions were available for programmers to use, but, I was always a "write my own routine" kind of guy. Kept my software tight and fast, with no dependencies beyond the bare minimums.

after I got out of it? Bloat was getting bad... seemed everyone was yanking in a half a gig of "stuff" just to use ONE little function they needed. Hey... whats a few lines of code to eliminate the dependency and tighten things up.

one quick and dirty way to accomplish it? decide your maximum number of places. Lets say its 16 places for the integer portion, and 8 places for the decimals.

simply concatenate... 16 zeroes, then your integer after stripping leading space... and add on 8 trailing zeroes.
just know where your first digit locationa and last digit location are, or count up and past the decimal point. No decimal point? Integer so  Add one.
Reply


Messages In This Thread
Printing leading zeroes - by bert22306 - 03-29-2023, 04:34 AM
RE: Printing leading zeroes - by mnrvovrfc - 03-29-2023, 05:10 AM
RE: Printing leading zeroes - by mdijkens - 03-29-2023, 07:51 AM
RE: Printing leading zeroes - by bplus - 03-29-2023, 01:39 PM
RE: Printing leading zeroes - by SMcNeill - 03-29-2023, 08:00 AM
RE: Printing leading zeroes - by bert22306 - 03-29-2023, 11:39 AM
RE: Printing leading zeroes - by bert22306 - 03-29-2023, 08:16 PM
RE: Printing leading zeroes - by mdijkens - 03-30-2023, 07:22 AM
RE: Printing leading zeroes - by MrCreemy - 04-23-2023, 07:15 PM



Users browsing this thread: 2 Guest(s)