Remove thousands separator

4 posts / 0 new
Last post
jabirulo
jabirulo's picture
Offline
Last seen: 1 day 6 hours ago
Joined: 2013-05-30 00:53
Remove thousands separator

Hi, I juts build a listviewer/listbrowser with name+size and size is a string 'cos I'm adding thousands separator: "aaaa" "123.456"...

Building size->text_with_thousands_separator I use:

  1. IUtility->SNPrintf(size_str, sizeof(size_str), "%lU", size); //using the locale's formatting conventions

So I get "123.456", but on lister to sort such column I must (or is there other way?) revert/remove the thousands separator char.
Now I use this ugly code:

  1. uint32 val1, val2;
  2. char *txt1, *txt2;
  3. char tmp[20];
  4. ...
  5. GetNodeData( obj, msg->Node1, msg->ColumnNr, LISTVIEWERN_Text,&txt1, TAG_END); //gets value from column
  6. ...
  7. int8 j = 0, k = 0;
  8. while(txt1[k] != '\0') { if( isdigit(txt1[k]) ) tmp[j++] = txt1[k]; ++k; }
  9. tmp[j] = '\0';
  10. IDOS->StrToLong(&tmp, &val1);
  11. ...

Any other way to "undo" such thousands separator?
TiA

msteed
msteed's picture
Offline
Last seen: 1 month 1 week ago
Joined: 2022-01-18 08:34
Re: Remove thousands separator

Maybe you could store the original integers as user data, and then sort on that instead of the formatted string?

trixie
trixie's picture
Offline
Last seen: 2 months 2 weeks ago
Joined: 2011-02-03 13:58
Re: Remove thousands separator

@jabirulo

How about you store the size (= the actual number) in each node's user data, and when you need to sort according to size you compare that, instead of the node text?

EDIT: msteed beat me to it! :-)

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

jabirulo
jabirulo's picture
Offline
Last seen: 1 day 6 hours ago
Joined: 2013-05-30 00:53
Re: Remove thousands separator

@msteed & @trixie

thx will try such approach.
BTW I'm using AEON's listviewer as list browser.

EDIT1; worked like a charm, THX guys!!!!
Using (struct) lvNode->Value for storing integer size value and comparing/sorting using "retval = msg->Node1->Value - msg->Node2->Value;"

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

Log in or register to post comments