ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   reverse ZO_LocalizeDecimalNumber ? (https://www.esoui.com/forums/showthread.php?t=10553)

sinnereso 05/29/23 11:34 AM

reverse ZO_LocalizeDecimalNumber ?
 
is there a built in function to return 10,000 back to 10000 something like ZO_LocalizeDecimalNumber?

Masteroshi430 05/29/23 11:46 AM

Quote:

Originally Posted by sinnereso (Post 47840)
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)
?

sinnereso 05/29/23 11:49 AM

Quote:

Originally Posted by Masteroshi430 (Post 47841)
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

sinnereso 05/29/23 11:54 AM

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,

Baertram 05/29/23 01:45 PM

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.

sinnereso 05/29/23 02:19 PM

Quote:

Originally Posted by Baertram (Post 47844)
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

Sharlikran 05/29/23 06:00 PM

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 },


Sharlikran 05/29/23 07:10 PM

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))


sinnereso 05/29/23 08:21 PM

Quote:

Originally Posted by Sharlikran (Post 47846)
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.

Sharlikran 05/29/23 09:55 PM

My second post shows how to go back and forth though, did you get a chance to try that?

Baertram 05/29/23 11:36 PM

Use choices and choicesValues! I described that in my other post of you in detail already.

sinnereso 05/30/23 08:42 AM

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.

ZOS_DanBatson 05/30/23 08:59 AM

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.

Masteroshi430 05/30/23 09:03 AM

Quote:

Originally Posted by ZOS_DanBatson (Post 47852)
French, I believe, uses hardspaces.

C'est tout à fait exact mon cher Dan. :D

Baertram 05/30/23 09:05 AM

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

sinnereso 05/31/23 07:36 AM

Quote:

Originally Posted by Baertram (Post 47854)
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.

Baertram 05/31/23 11:09 AM

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.

sinnereso 05/31/23 12:41 PM

Quote:

Originally Posted by Baertram (Post 47856)
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 :)


All times are GMT -6. The time now is 11:33 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI