project-navigation
Personal tools

Author Topic: Mod that comma delimits some monetary amounts  (Read 4791 times)

Offline ChickenLiver

  • Cannon Fodder
  • **
  • Posts: 2
    • View Profile
Mod that comma delimits some monetary amounts
« on: February 20, 2010, 02:28:12 am »
Not really sure this is the right forum for this, as it requires recompilation, but I'm not submitting it as a patch because of the possibility it breaks some po files...Anyways...


Here's a small mod that adds thousand separators to some prices.  Separator character and placement is based on regional settings.  Stats screen, purchase screen, the credits display at the top, and only one or two other places currently affected.  Makes it easier to parse large values, in my opinion.  Replacing "*cvar:value" with "*cvar:formatInt:value" in *.ufo files will use thousand separators on integers.  Note that it presumably only works in string fields, and not in functions.  The way I modified the ufo syntax is a bit of a hack, but it works.

Not sure if I'll extend this to other screens that display prices.  If anyone else cares to play with it, it's basically just replacing "variantOfSprintf(string, _("Possibly some stuff\t %i c"), cost)" with "variantOfSprintf(string, _("Possibly some stuff\t %s c"), FormatInt(cost))" all over the place.  Note that this might cause issues with some of the translations in po files.

It also fixes a few minor bugs:  No gap between number and c in max debits allowed and no terminating "c" at all on funding screen.  Also, there was a bug in string length checking in Com_MacroExpandString().

Requires recompilation to run, unfortunately.
« Last Edit: February 20, 2010, 11:25:42 pm by ChickenLiver »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Mod that comma delimits some monetary amounts
« Reply #1 on: February 20, 2010, 09:10:23 am »
please post patches - not full files

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Mod that comma delimits some monetary amounts
« Reply #2 on: February 20, 2010, 09:12:03 am »
a comma will not work in every language - you should use locales for this. also please watch out the coding guidelines (they are in the coding section of the wiki)

Offline ChickenLiver

  • Cannon Fodder
  • **
  • Posts: 2
    • View Profile
Re: Mod that comma delimits some monetary amounts
« Reply #3 on: February 20, 2010, 11:26:12 am »
Thanks for the suggestions.  I would have used the locale in the first place, but I've always found it rather difficult to find the relevant docs on such things.  Managed to find the function, however, and I'm now using it.

I'm using the numeric locale information rather than the currency specific information, because credits are being used instead of the locale's currency.  In the US, for example, prefixing the credit amount with 'c' instead of '$' would just look bizarre.

Also fixed up the style, and formatted a couple other large numbers.

Updated diff attached to first post.
« Last Edit: February 20, 2010, 11:48:57 am by ChickenLiver »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools