We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › decimal separation in different languages
Page Index Toggle Pages: 1
decimal separation in different languages (Read 340 times)
decimal separation in different languages
Feb 17th, 2008, 12:08am
 
I am not able to find any previous discussion about this argument not in discourse nor in FAQ, so I don't know if anyone already solved this kind of problem.

I'm using Processing 0135 on Mac OSX 10.5.2 in italian language, with Interfascia 003 user interface library.

I wrote this code to range check the input on a text field:

float RangeCheckFloat(String Data, float Min, float Max)
{
   float FloatNum = 0;
   if (Data.length() != 0)
   {
     FloatNum = Float.parseFloat(Data);
     if (FloatNum < Min) FloatNum = Min;
     if (FloatNum > Max) FloatNum = Max;
     TxFlag = true;
   }
   return FloatNum;
}

the function is called in this way:

   BtnSendSpeed.update();
   if (BtnSendSpeed.released)
   {
     DesSpeed = RangeCheckFloat(InputSpeed.getValue(), -500, 500);
     InputSpeed.setValue(nf(DesSpeed,5,2));
   }
   BtnSendSpeed.display();

So, nf() translates the float value with "," (comma) decimal separation. Reading again the input field with Float.parseFloat(Data), it returns an error because it looks for a "." decimal separator.

Is there any way (other then permanently change OS language) to make both the functions working in the same way?

A working simulation example of what I'm trying to do, can be found here:
http://xoomer.alice.it/guiott/Rino/dsNavCon/applet/index.html

Thank you in advance to anyone who will help me.


Page Index Toggle Pages: 1