Former Member
inherit
guest@proboards.com
259598
0
Nov 27, 2024 1:58:49 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Sept 19, 2021 1:29:18 GMT -8
techdot.proboards.com/As title says I need to convert number like 1000 to 1k or 1252 to 1.2k Problem is on mini-profile only. example: from this to this:
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,018
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Sept 19, 2021 1:40:36 GMT -8
Template Variable Functions We added an easier way to handle variables in our templating engine, with a new and expandable feature. Taking a variable, you can utilize additional functions on top of it: $[variable.(nohtml)] - will change HTML into nohtml (you will see the actual HTML code displayed, rather than rendered). $[variable.(attr_value)] - You will see the value parsed as an attribute value (removes certain symbols that would break attributes) $[variable.(commify)] - Only applicable to numbers, will add commas to a large number as needed. The number 10000 would thus display as 10,000. $[variable.(short_number)] - Only applicable to numbers, will shorten a very large number and abbreviate it. The number 10000 would thus display as 10K. Eton Bones Eton Bones Eton Bones Eton Bones Eton Bones Eton Bones" EDIT: If you're looking to modify a number via javaScript rather than through templating variable then you can utilize the _formatFileSize internal function of the fileupload jqueryUI widget: $.blueimpUI.fileupload.prototype._formatFileSize({size:1234*5432}); //returns "6.39 MB"
Just be aware that it uses the true factor (1024 == 1K) not the marketing gimmick of HD manufacturers (1000 == 1K) to make their hard drives look bigger than they really are.
|
|
Former Member
inherit
guest@proboards.com
259598
0
Nov 27, 2024 1:58:49 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Sept 19, 2021 2:45:31 GMT -8
Template Variable Functions We added an easier way to handle variables in our templating engine, with a new and expandable feature. Taking a variable, you can utilize additional functions on top of it: $[variable.(nohtml)] - will change HTML into nohtml (you will see the actual HTML code displayed, rather than rendered). $[variable.(attr_value)] - You will see the value parsed as an attribute value (removes certain symbols that would break attributes) $[variable.(commify)] - Only applicable to numbers, will add commas to a large number as needed. The number 10000 would thus display as 10,000. $[variable.(short_number)] - Only applicable to numbers, will shorten a very large number and abbreviate it. The number 10000 would thus display as 10K. EDIT:If you're looking to modify a number via javaScript rather than through templating variable then you can utilize the _formatFileSize internal function of the fileupload jqueryUI widget: $.blueimpUI.fileupload.prototype._formatFileSize({size:1234*5432}); //returns "6.39 MB"
Just be aware that it uses the true factor (1024 == 1K) not the marketing gimmick of HD manufacturers (1000 == 1K) to make their hard drives look bigger than they really are. Thank you for reply,but I can't really figure it out how to add that line $[variable.(short_number)]
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 20, 2021 10:46:53 GMT -8
EDIT:If you're looking to modify a number via javaScript rather than through templating variable then you can utilize the _formatFileSize internal function of the fileupload jqueryUI widget: $.blueimpUI.fileupload.prototype._formatFileSize({size:1234*5432}); //returns "6.39 MB"
Just be aware that it uses the true factor (1024 == 1K) not the marketing gimmick of HD manufacturers (1000 == 1K) to make their hard drives look bigger than they really are. Thank you for reply,but I can't really figure it out how to add that line $[variable.(short_number)] you would go to your mini profile here https://techdot.proboards.com/admin/themes/1/advanced and look for $[user.posts] and I guess change it to this if I follow correctly $[user.posts.(short_number)]
|
|
inherit
257284
0
Nov 13, 2024 10:37:51 GMT -8
Eton Bones
70
December 2018
etonbones
|
Post by Eton Bones on Sept 20, 2021 16:04:09 GMT -8
$[user.posts.(short_number)] would not work because that outputs text for display not an actual number $[user.last_online.timestamp.(short_number)] works because that outputs an actual number but that means this feature is pretty niche since most of the variable outputs are not numbers Unless there is something that can de-commify or somehow cast that text back to a number ( Matej ?) the addition/subtraction comparison that is also mentioned in that PB Update would also be something that would not see many usable scenarios. The javascript approach is probably the best bet but perhaps with some minimum (100,000 maybe) in place so you don't get some someone with 9 posts getting converted to "0.008 K" or "0.009 K" (depending on which factor you use)
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 20, 2021 18:56:55 GMT -8
$[user.posts.(short_number)] would not work because that outputs text for display not an actual number $[user.last_online.timestamp.(short_number)] works because that outputs an actual number but that means this feature is pretty niche since most of the variable outputs are not numbers Unless there is something that can de-commify or somehow cast that text back to a number ( Matej ?) the addition/subtraction comparison that is also mentioned in that PB Update would also be something that would not see many usable scenarios. The javascript approach is probably the best bet but perhaps with some minimum (100,000 maybe) in place so you don't get some someone with 9 posts getting converted to "0.008 K" or "0.009 K" (depending on which factor you use) Maybe I'm not sure of your goals but K is a letter. It is displayed as text. The theme modification is html which is displayed as text. It does the conversion of the number into text after rounding. How is it not suitable for your purposes?
|
|
inherit
257284
0
Nov 13, 2024 10:37:51 GMT -8
Eton Bones
70
December 2018
etonbones
|
Post by Eton Bones on Sept 20, 2021 22:22:00 GMT -8
Maybe I'm not sure of your goals but K is a letter. It is displayed as text. The theme modification is html which is displayed as text. It does the conversion of the number into text after rounding. How is it not suitable for your purposes? P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ , it has nothing to do with "K" that would be in the final output. The issue here is that the theme modification is pointless if the promised conversion does not work as advertised and it is quite clear $[user.posts] does not output a number which is why the .(short_number) method does not work on it (spoiler: it outputs actual text with commas and not just cast to text for inclusion in Html. This is why the announcement regarding this new feature was very specific in saying it required a number to work). If dubious, I gave an example of a variable that does indeed output a real number which does respond to the .(short_number) method which you can easily preview in a template to see which one works and which one doesn't. @kolle998 , I coded a GLOBAL FOOTER script using the second method that was suggested and added some options to get around a few obstacles: <script> /* Shorten High Post Count Numbers */ /* Coded for the redesigned ellimccale.com theme at techdot.proboards.com */ $(function () { const minimum_to_convert = 10000; const bytes_in_1K = 1000; const decimal_places = 0; const magnitude_suffix = ["","K", "M", "G"];
function convert_user_posts_count(){ $('.posts-txt:not([data-post-count])').each((i, f) => { let t = $(f).text(), magnitude = magnitude_suffix.length; f.dataset.postCount = f.innerText; t.indexOf(',')!=-1 && $(f).text((function (e) { f.title=f.innerText; return void 0 === e.size ? "" : (function(e){ while(--magnitude){ if(Math.pow(bytes_in_1K, magnitude) <= e.size){ return (e.size / Math.pow(bytes_in_1K, magnitude)).toFixed(decimal_places) + magnitude_suffix[magnitude] } } return ""; })(e) })({ size: Number((""+ t).replace(/\,/g, '').trim()) })) })} pb.events.on('afterSearch', convert_user_posts_count), convert_user_posts_count(); }); </script> If desired it can be converted to a plugin. NOTES: -
utilizes the .post-text class unique to elli 's theme
-
a title attribute is added for any converted value so one can still hover over the number to see the full value
-
a data-post-count attribute is added to guard against double conversions (not likely) but that can also be added manually in layout template or through 3rd party code to exempt a specific user's post counts from being shortened
const minimum_to_convert = 10000; sets the minimum a post count must reach before getting the conversion treatment
const bytes_in_1K = 1000; sets the conversion factor to 1000 (note: 1024 bytes in a kilobyte is the standard)
const decimal_places = 0; sets how many decimal places you want displayed (e.g. a value of 2 would yield "612.25K" while a value of 0 would yield "612K" )
const magnitude_suffix = ["","K", "M", "G"]; sets the suffix used when shortening a post count and ordered in increasing level of magnitude. Normally it is a 2-letter suffix such as "KB" but from your image, I assume you wanted the single letter version. Should you want to support larger magnitudes such as terabytes or even petabytes (not likely) those can be added
|
|
Former Member
inherit
guest@proboards.com
259598
0
Nov 27, 2024 1:58:49 GMT -8
Former Member
0
January 1970
Former Member
|
Post by Former Member on Sept 21, 2021 2:35:37 GMT -8
Maybe I'm not sure of your goals but K is a letter. It is displayed as text. The theme modification is html which is displayed as text. It does the conversion of the number into text after rounding. How is it not suitable for your purposes? P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ , it has nothing to do with "K" that would be in the final output. The issue here is that the theme modification is pointless if the promised conversion does not work as advertised and it is quite clear $[user.posts] does not output a number which is why the .(short_number) method does not work on it (spoiler: it outputs actual text with commas and not just cast to text for inclusion in Html. This is why the announcement regarding this new feature was very specific in saying it required a number to work). If dubious, I gave an example of a variable that does indeed output a real number which does respond to the .(short_number) method which you can easily preview in a template to see which one works and which one doesn't. @kolle998 , I coded a GLOBAL FOOTER script using the second method that was suggested and added some options to get around a few obstacles: <script> /* Shorten High Post Count Numbers */ /* Coded for the redesigned ellimccale.com theme at techdot.proboards.com */ $(function () { const minimum_to_convert = 10000; const bytes_in_1K = 1000; const decimal_places = 0; const magnitude_suffix = ["","K", "M", "G"];
function convert_user_posts_count(){ $('.posts-txt:not([data-post-count])').each((i, f) => { let t = $(f).text(), magnitude = magnitude_suffix.length; f.dataset.postCount = f.innerText; t.indexOf(',')!=-1 && $(f).text((function (e) { f.title=f.innerText; return void 0 === e.size ? "" : (function(e){ while(--magnitude){ if(Math.pow(bytes_in_1K, magnitude) <= e.size){ return (e.size / Math.pow(bytes_in_1K, magnitude)).toFixed(decimal_places) + magnitude_suffix[magnitude] } } return ""; })(e) })({ size: Number((""+ t).replace(/\,/g, '').trim()) })) })} pb.events.on('afterSearch', convert_user_posts_count), convert_user_posts_count(); }); </script> If desired it can be converted to a plugin. NOTES: utilizes the .post-text class unique to elli 's theme a title attribute is added for any converted value so one can still hover over the number to see the full value a data-post-count attribute is added to guard against double conversions (not likely) but that can also be added manually in layout template or through 3rd party code to exempt a specific user's post counts from being shortened
const minimum_to_convert = 10000; sets the minimum a post count must reach before getting the conversion treatment
const bytes_in_1K = 1000; sets the conversion factor to 1000 (note: 1024 bytes in a kilobyte is the standard)
const decimal_places = 0; sets how many decimal places you want displayed (e.g. a value of 2 would yield "612.25K" while a value of 0 would yield "612K" )
const magnitude_suffix = ["","K", "M", "G"]; sets the suffix used when shortening a post count and ordered in increasing level of magnitude. Normally it is a 2-letter suffix such as "KB" but from your image, I assume you wanted the single letter version. Should you want to support larger magnitudes such as terabytes or even petabytes (not likely) those can be added
Well Eton Bones thank you so much,code work perfectly,just what I needed.
|
|
#e61919
Product Manager
12218
0
1
Mar 11, 2017 17:47:30 GMT -8
Matej
This is my status!
17,630
August 2003
wooper
|
Post by Matej on Sept 21, 2021 10:06:09 GMT -8
$[user.posts.(short_number)] would not work because that outputs text for display not an actual number $[user.last_online.timestamp.(short_number)] works because that outputs an actual number but that means this feature is pretty niche since most of the variable outputs are not numbers Unless there is something that can de-commify or somehow cast that text back to a number ( Matej ?) the addition/subtraction comparison that is also mentioned in that PB Update would also be something that would not see many usable scenarios. The javascript approach is probably the best bet but perhaps with some minimum (100,000 maybe) in place so you don't get some someone with 9 posts getting converted to "0.008 K" or "0.009 K" (depending on which factor you use) To use the number with posts and likes you can use: $[user.posts_count.(short_number)] $[user.likes_count.(short_number)] Both of the _count variables output a pure number and can then run the functions on them. This will be clearer in v6. We had to take this route to not break existing user.posts implementations.
|
|