[ProgClub programming] numformat.php

John Elliot V | ProgClub jj5 at progclub.org
Sun Jun 2 16:55:10 AEST 2019


PHP has str_pad() for aligning strings...

 https://www.php.net/manual/de/function.str-pad.php

I think alignment would require various "modes" passed as command-line
flags. One mode could just pad every number X amount (e.g. 20 per your
suggestion); another mode could assume the data is in space-separated
columns, and calculate max column width.

On 2/6/19 4:36 pm, Jevan Pipitone wrote:
> https://www.php.net/manual/en/function.printf.php
> 
> You could use printf to right justify a number.
> 
> echo printf("%20f",number_format( floatval( $trimmed ), $dec_points ));
> 
> I haven't actually tried it, let me know if it works. The idea is that
> each number would be made to take up 20 columns with spaces added to the
> left to fill in where necessary.
> 
> https://stackoverflow.com/questions/20024938/how-to-align-a-float-value-in-c
> 
> (assuming the C printf is similar to the php printf)
> 
> Jevan.
> 
> 
> On Sun. 02-Jun.-19 12:56 pm, John Elliot V | ProgClub wrote:
>> So I was trying to read some ZFS debugging info from:
>>
>>  /proc/spl/kstat/zfs/arcstats
>>
>> which looked something like this:
>>
>>  13 1 0x01 96 4608 22091036583 580294752449707
>>  name                            type data
>>  hits                            4    2244288547
>>  misses                          4    72988333
>>  demand_data_hits                4    35769925
>>  demand_data_misses              4    3439818
>>  demand_metadata_hits            4    2188909634
>>  demand_metadata_misses          4    59434568
>>
>> and I was having trouble gauging the order of magnitude of the numbers
>> so I wrote numformat.php:
>>
>>  https://svn.jj5.net/jjrepo/jj5-bin/branches/0.2/bin/numformat.php
>>
>> which formats numerical content like this:
>>
>>  root at orac:/home/jj5# numformat.php < /proc/spl/kstat/zfs/arcstats
>>  13 1 0x01 96 4,608 22,091,036,583 580,436,679,049,214
>>  name                            type data
>>  hits                            4    2,244,304,800
>>  misses                          4    72,989,311
>>  demand_data_hits                4    35,770,479
>>  demand_data_misses              4    3,439,818
>>  demand_metadata_hits            4    2,188,925,033
>>  demand_metadata_misses          4    59,434,568
>>
>> It would be nice if I could right-align numbers too, but I'm not that
>> clever... :)
>>
>> May the Force be with you,
>> John Elliot V
>>
>> _______________________________________________
>> ProgClub programming
>> programming at progclub.org
>> https://www.progclub.org/cgi-bin/mailman/listinfo/programming
>> https://www.progclub.org/
> -- 
> Signature
> 
> 
> Volunteer Work Only (but you can make money)
> MIT SE (UC), GradDip IT (UC), BSc (ANU),
> GradCert Rsch Methods & Des (UC)
> 
> I am here for online friends, hobbies, volunteer work, and working on
> business ideas, and I am on Centrelink Disability Support Pension
> (Schizophrenia & Aspergers). I suspect that what will probably work is
> people who are on a Centrelink payment such as unemployed, disability,
> or retired, since they can benefit from me and since it allows me to
> give back to Centrelink, and also, if female friends then age 49+ and
> less attractive so that they will find me attractive, also probably
> overweight since I am overweight. However I can also work with highly
> skilled people since I can make use of what I get from them that is
> useful for me to be able to work with interesting concepts. Me:
> Computing Researcher, Self Employed, Innovation, Management, Canberra
> Australia. Interests: Especially things involving the use of a computer.
> Creating, Doing, Improvising, Analysing for Improvement: Computer
> Programming Open Source including C#/VB.NET, CSS, HTML, Javascript, MS
> Visual Studio, My/MS Sql, PHP, WinForms, WPF. 3d animation, Acting
> Improvisations, Audio Podcasts, Business & Startups, Chat, Creative
> Writing & Poetry, Creativity, Dancing, Debating, Decisions, Digital Art,
> Discussion of Topics, Electronic Music Composition/Creation (FL Studio),
> Engineering, Friends, Ideas, Information Analysis, Innovation, IT
> Tuition, Jazz Piano, Jazz Singing Male Baritone & Choir & Karaoke,
> Management, PC Support, Photography, Public Speaking, Reading online
> science magazines and emails, Research, Science, Making YouTube Videos.
> Friendship with adults via phone, Email, Online Chat, anything we can
> make and send each other and collaborate on. Note: For our interactions,
> collaborations, hobbies, volunteer work, etc to turn out successful, it
> may be necessary for there to be a financial cost to me in order for you
> or your organization to make it work, so let me know what you suggest.
> 
> Web: http://www.jevan.com.au/
> Email: email5 at jevan.com.au <mailto:email5 at jevan.com.au>
> Tel: (02) 6152 8010 (or +61 2 6152 8010)
> LinkedIn: http://www.linkedin.com/in/jevanpipitone
> Facebook: http://www.facebook.com/jevanpipitone
> GitHub: http://www.github.com/jevanpipitone
> Twitter: http://www.twitter.com/jevanpipitone
> Canberra, Australia
> 
> 
> 
> _______________________________________________
> ProgClub programming
> programming at progclub.org
> https://www.progclub.org/cgi-bin/mailman/listinfo/programming
> https://www.progclub.org/
> 

-- 
|_|O|_| ProgClub
|_|_|O| Because every programmer needs a good club!
|O|O|O| https://www.progclub.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jj5.vcf
Type: text/x-vcard
Size: 231 bytes
Desc: not available
URL: <http://www.progclub.org/pipermail/programming/attachments/20190602/cb380909/attachment.vcf>


More information about the programming mailing list