Thread Tools Display Modes
05/29/23, 11:34 AM   #1
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Question reverse ZO_LocalizeDecimalNumber ?

is there a built in function to return 10,000 back to 10000 something like ZO_LocalizeDecimalNumber?
  Reply With Quote
05/29/23, 11:46 AM   #2
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Originally Posted by sinnereso View Post
is there a built in function to return 10,000 back to 10000 something like ZO_LocalizeDecimalNumber?
Apparently not, ZO_LocalizeDecimalNumber is indeed ZO_CommaDelimitDecimalNumber and returns a string, did you try :
tonumber(value)
?
  Reply With Quote
05/29/23, 11:49 AM   #3
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by Masteroshi430 View Post
Apparently not, ZO_LocalizeDecimalNumber is indeed ZO_CommaDelimitDecimalNumber and returns a string, did you try :
tonumber(value)
?
I'll try it. Im just trying to display 10,000 in libaddonmenu settings panel but save 10000 as the variable used in math in other functions. So i want to SetFunction to be able to return it to 10000 basically
  Reply With Quote
05/29/23, 11:54 AM   #4
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Doesn't appear to work.

It's not critical but I prefer to have numbers in 10,000 format for asthetics. numbers like 10000 in a dropdown looks cheese. Its just for a new telvar reserve feature for Xmultiplier telvar farming but want it to look guud =p. Its perfectly functional now without comma.

ill continue with no comma for now unless we find something genius.

its basically this line that needs the tweak to non comma delimited number like 10000:

Code:
setFunc = function(var) MyAddon.savedVariables.telvarReserve = tonumber(var) end,

Last edited by sinnereso : 05/29/23 at 12:03 PM.
  Reply With Quote
05/29/23, 01:45 PM   #5
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,965
If you want to remove the delimiter it should be enough to use tonumber function.
But if you want to save and show it differently you cannot use both, with delimiter and without in your same 1 SavedVars variable!

Your SavedVars should save with tonumber and your getFunc needs to convert the visual parts to show with the delimiter then (get SV, convert to with delimiter, return in getFunc). And in setFunc do the opposite.
  Reply With Quote
05/29/23, 02:19 PM   #6
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by Baertram View Post
If you want to remove the delimiter it should be enough to use tonumber function.
But if you want to save and show it differently you cannot use both, with delimiter and without in your same 1 SavedVars variable!

Your SavedVars should save with tonumber and your getFunc needs to convert the visual parts to show with the delimiter then (get SV, convert to with delimiter, return in getFunc). And in setFunc do the opposite.
ok the saved variables are working with the tonumber.. where I'm having the issue now is with the "choices" in the dropdown. It doesn't like entries like 1,000, 10,000.

ive tried:

Code:
choices = {"0", "100", "1,000", "10,000"},
choices = {0, 100, 1,000, 10,000},
choices = {0, 100, (1,000), (10,000)},

and

choices = {0, 100, ZO_LocalizeDecimalNumber(1000), ZO_LocalizeDecimalNumber(10000)}, << which displays perfectly but i think its saving the function with the value in the variable.
any suggestions to display comma delimited in the choices? I've tried everythign I can think of.

**EDIT Hmm maybe i'll just save the variables with commas and use the tonumber once in the banking code to convert it back there.. unless u can think of another way to format the "choices" line

Last edited by sinnereso : 05/29/23 at 02:24 PM.
  Reply With Quote
05/29/23, 06:00 PM   #7
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 642
I really recommend against mixing formats like that. Anything can be stored at a number like 10000 or 1000 anywhere you want. For a table for LibAddonMenu, in the saved variables, anything. When displaying the number then use the zo_xxx function. Otherwise you will be going back and forth all over the place. For example comparing 10,000 vs 10000 and so on.

Another thing though is if the value is not going to change then use a constant

local YOURMODNAME_VALUE_TEN_THOUSAND = 10000
Code:
choices = {"0", "100", "1,000", ZO_LocalizeDecimalNumber(YOURMODNAME_VALUE_TEN_THOUSAND) },
choicesValues= {"0", "100", "1,000", YOURMODNAME_VALUE_TEN_THOUSAND },

Last edited by Sharlikran : 05/29/23 at 06:04 PM.
  Reply With Quote
05/29/23, 07:10 PM   #8
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 642
Also go to an online Lua compiler

Code:
local value = "10,000"
print(tonumber(value))
That will return nil

Code:
local value = "10,000"
value = string.gsub(value, ",", "")
print(tonumber(value))
That will return 10000

Code:
local value = "10,000"
value = value:gsub(",", "")
print(tonumber(value))
Even that if you want

Also you probably want to use Regex because that will only work for English with a comma. It won't work for any foreign number with a period for the separator.

Code:
local value = "10.000"
value = value:gsub("[%p%c%s]", "")
print(tonumber(value))

Last edited by Sharlikran : 05/29/23 at 07:16 PM.
  Reply With Quote
05/29/23, 08:21 PM   #9
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by Sharlikran View Post
I really recommend against mixing formats like that. Anything can be stored at a number like 10000 or 1000 anywhere you want. For a table for LibAddonMenu, in the saved variables, anything. When displaying the number then use the zo_xxx function. Otherwise you will be going back and forth all over the place. For example comparing 10,000 vs 10000 and so on.

Another thing though is if the value is not going to change then use a constant

local YOURMODNAME_VALUE_TEN_THOUSAND = 10000
Code:
choices = {"0", "100", "1,000", ZO_LocalizeDecimalNumber(YOURMODNAME_VALUE_TEN_THOUSAND) },
choicesValues= {"0", "100", "1,000", YOURMODNAME_VALUE_TEN_THOUSAND },
I'm happy to store it as 10000 because I use it in other functions mathematically. Im merely trying to display it in 10,000 format in a libaddonmenu dropdown list. The problem is it then uses the selected value to save it again. So I'm trying to display in panel like this 10,000 and then convert back to 10000 after selected. I think my hurdle atm is HOW to display 10,000 in the "choices" without it going wonky from all the extra commas and have whats there ONLy save the number not the function as well to the variable.

Ive currently left it as 10000 everywhere and working fine. Just looks like crap in the settings imo.
  Reply With Quote
05/29/23, 09:55 PM   #10
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 642
My second post shows how to go back and forth though, did you get a chance to try that?
  Reply With Quote
05/29/23, 11:36 PM   #11
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,965
Use choices and choicesValues! I described that in my other post of you in detail already.
  Reply With Quote
05/30/23, 08:42 AM   #12
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
The choices & choicesValues worked perfectly . I tried some of Sharlikrans stuff but was having issues with the setfunction saving those functions as well which wasn't playing nice with the banking code.
  Reply With Quote
05/30/23, 08:59 AM   #13
ZOS_DanBatson
ZOS Staff!
 
ZOS_DanBatson's Avatar
Yes this person is from ZeniMax!
Join Date: Jul 2015
Posts: 179
Note: there's an expectation with ZO_CommaDelimitNumber and ZO_CommaDelimitDecimalNumber that the result would at some point make its way into a grammar call in an arg of the format <<f:1>>, because grammar will automatically convert the , and . to the appropriate delimiter for the user's language (some languages swap the . and the , from what English uses. French, I believe, uses hardspaces.) ZO_FastFormatDecimalNumber uses already localized delimiters so you can skip the call to grammar.

All that to say make sure you know whether the string you're working with is before or after being localized. Because if it's after, just using gsub to replace ',' with '' will replace the decimal, not the thousands separators, in some languages. If it's after localization, consider using GetString(SI_DIGIT_GROUP_SEPARATOR) for your gsub.
  Reply With Quote
05/30/23, 09:03 AM   #14
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Originally Posted by ZOS_DanBatson View Post
French, I believe, uses hardspaces.
C'est tout à fait exact mon cher Dan.
  Reply With Quote
05/30/23, 09:05 AM   #15
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,965
Moved your thread and some others to lua / xml questions. Please use this forum in the future if you got general questions about coding, instead of the addon help forum which is there for addon related questions or to get help with an addon (non devs). Thank you
  Reply With Quote
05/31/23, 07:36 AM   #16
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by Baertram View Post
Moved your thread and some others to lua / xml questions. Please use this forum in the future if you got general questions about coding, instead of the addon help forum which is there for addon related questions or to get help with an addon (non devs). Thank you
Im easy. Put it where you like it but this was specifically about help with my addon and more specifically a settings panel issue.
  Reply With Quote
05/31/23, 11:09 AM   #17
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,965
Addon help forums is for users asking questions about addons or installing addons, non working addons etc. and not about developers asking for coding instructions and help to code their addons. Therefor you (and other threads I moved :-) ) got the authoring discussion (The place to ask general questions about developing AddOns) and the lua/XML help ( The place to ask specific questions about lua development) forums.

Last edited by Baertram : 05/31/23 at 11:58 AM.
  Reply With Quote
05/31/23, 12:41 PM   #18
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by Baertram View Post
Addon help forums is for users asking questions about addons or installing addons, non working addons etc. and not about developers asking for coding instructions and help to code their addons. Therefor you (and other threads I moved :-) ) got the authoring discussion (The place to ask general questions about developing AddOns) and the lua/XML help ( The place to ask specific questions about lua development) forums.
OH! kk got it
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » reverse ZO_LocalizeDecimalNumber ?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off