INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: isrange() doesn't work due to locale settings [Solved]  (Read 1716 times)

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
isrange() doesn't work due to locale settings [Solved]
« on: September 21, 2013, 01:49:11 pm »

This isn't the first time, like here for example. In that thread a regex solved the issue that replaces a comma with a dot.

This time its in a custom field, [Album DR]. It gives a value with 2 decimals with a comma instead of a dot. I've been trying to wrap my head around the regex and I've been reading the wiki on regex() but I can't figure it out.

Some help with this would be appreciated.

Tx!
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: isrange() doesn't work due to locale settings
« Reply #1 on: September 21, 2013, 01:56:35 pm »

If you just want to replace comma's with dots, use Replace(value, /,, .).

If there is something other than this, can you show the example values, etc.?
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: isrange() doesn't work due to locale settings
« Reply #2 on: September 21, 2013, 02:27:31 pm »

Funny, I didn't expect that to work as its an operation on a string. I guess I could have known it would work as removing the last 3 also evaluates it as an int.

Initially I made it work by removing the last 3 characters:
if(compare(RemoveRight([Album DR],3),<,7),<font color="FF0000">Album DR: [Album DR]<//font>,if(isrange(RemoveRight([Album DR],3),8-11),<font color="FFD800">Album DR: [Album DR]<//font>,if(icompare(RemoveRight([Album DR],3),>,11),<font color="4CFF00">Album DR: [Album DR]<//font>,[Album DR])))

I replaced it with
if(compare(replace([Album DR],/,,.),<,7),<font color="FF0000">Album DR: [Album DR]<//font>,if(isrange(replace([Album DR],/,,.),8-11),<font color="FFD800">Album DR: [Album DR]<//font>,if(icompare(Replace([Album DR],/,,.),>,11),<font color="4CFF00">Album DR: [Album DR]<//font>,[Album DR])))

Seems to work fine.

Makes me wonder though, does MC dynamically convert strings to integers? With the comma it was evaluated as a string, remove 3 trailing chars and it works as an integer. Replace the comma with a dot also works as an integer. Smart.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: isrange() doesn't work due to locale settings
« Reply #3 on: September 21, 2013, 03:24:31 pm »

MC doesn't have strong typing in the expression language, which works primarily with strings of characters.  When necessary, I opportunistically converts these strings into numbers, but only if the conversion works and only as much as makes sense.  For example:

compare(3, >, 2)  => 1
compare(3x, >, 2) => 1
compare(x3, >, 2) => 0

Here's a trick using a saved variable to avoid the repeated sub-expressions, and I've rewritten the expression to use ifelse():

save(replace([Album DR],/,,.), val)/
ifelse(
    compare([val],<,7),
       <font color="FF0000">Album DR: [Album DR]<//font>,
    compare([val],>,11),
       <font color="4CFF00">Album DR: [Album DR]<//font>,
    isrange([val],8-11),
       <font color="FFD800">Album DR: [Album DR]<//font>,
    1,
        [Album DR]
)
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: isrange() doesn't work due to locale settings
« Reply #4 on: September 21, 2013, 03:34:42 pm »

Ah very elegant. That's one I need to remember as I tend to fiddle with nested if's a lot.

Just noticed 7 to 7.99 wasn't included ;).

Tx.

Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: isrange() doesn't work due to locale settings
« Reply #5 on: September 21, 2013, 03:45:08 pm »

I noticed you also has "icompare" above.  Typo fixed.
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: isrange() doesn't work due to locale settings
« Reply #6 on: September 21, 2013, 03:58:52 pm »

That's funny, I hadn't noticed that because its working fine with that typo :). I would think since that eval result is false, text should be the default grey but its green.

I must be missing something...  ?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: isrange() doesn't work due to locale settings
« Reply #7 on: September 21, 2013, 04:11:00 pm »

Try these to see what's happening:

if(i0, T, F)
if(i1, T, F)

The strings "i0" and "i1" when evaluated as Boolean values always result in true.
Logged
The opinions I express represent my own folly.

InflatableMouse

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3978
Re: isrange() doesn't work due to locale settings
« Reply #8 on: September 21, 2013, 04:33:31 pm »

Ah I see it. It's evaluating this as a string: "icompare(Replace([Album DR],/,,.),>,11)" and since there's nothing to compare with, it's true, right?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: isrange() doesn't work due to locale settings
« Reply #9 on: September 21, 2013, 06:36:27 pm »

Ah I see it. It's evaluating this as a string: "icompare(Replace([Album DR],/,,.),>,11)" and since there's nothing to compare with, it's true, right?

The "compare" function is found and used - MC's expression parser finds the first possible longest match when looking for function names; so icompare(...) results in appending an "i" to the output of the compare() function's resultant output string.

This isn't a common scripting language syntax, as there are built-in ambiguities.  Almost all scripting languages use terminators and separators to help the language parser and to avoid such ambiguities.

As far as the truth value of an arbitrary string, that's just the way its defined.  If there is a value, any non-zero value, it is considered as a TRUE value in an If() statement.  This isn't uncommon.  In otherwords, there are only two FALSE conditions: 0 and empty.  Everything else is TRUE.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up