String::getFloatValue do not handle decimal comma

Hi,

readDoubleValue in juce_CharacterFunctions.h do not handle the comma as a decimal separtor

While I agree this should not depend on locale, could it make sens to support both decimal character ?

Thanks !

3 Likes

I am not sure if I conform to that curtailment.

But one could think of a heuristic, if only a comma or dot is present, treat it as decimal, otherwise as thousands separator, unless placed in wrong positions.

1 Like

bump :slight_smile:

If this is changed based on locale setting or heuristic detection, I predict horrible bugs in productive code.
Better add specialised functions, readDoubleHeuristic, readDoubleLocale etc…

why not

Maybe something like

enum class Format
{
  Locale,
  en,
  de, 
  // ...
};
String::getFloatValue (Format f = Format::Locale);

Or even allow a static setting:

void setDefaultValueFormat (Format f);

Or to keep backward compatibility set it to Format::en

This could be a horrible breaking change if JUCE just starts deciding to treat , as decimals.

E.g. you could be reading a row of a CSV and doing something like:

juce::String {"1,2,3,4"}.getFloatValue();

At the moment, this would return 1.0f (I think) whereas the proposed changes would have it return 1.2f.

Of course it’d be a bit of an odd thing to be parsing a string like that, but who knows what crazy things people are doing. It’s not like they’d be relying on a bug because that is currently the expected behaviour of those parsing functions.

Maybe a quick-n-easy solution is to add an optional argument to getFloatValue() that takes a list of decimal place characters?

juce::String {"1,2,3,4"}.getFloatValue ();
// returns 1.0f

juce::String {"1,2,3,4"}.getFloatValue ({'.', ','});
// returns 1.2f
1 Like

Using localisation seems like a nice idea, but it should be an opt-in kind of thing, not the default behaviour.

We’ve had feedback in the past where customers don’t want the app translated into their own language (for various reasons, e.g. it’s harder to follow English tutorials).

1 Like