[solved] Need help with float

7 years 11 months ago - 7 years 11 months ago #720 by Xavier
Please help!
The mono compiler doesn't let me enter float constants. I have to write this:
const float val = 566f/10f;

public void Setup () 
{
  Console.WriteLine ("Value={0:F2}",val);
}
If I write:
const float val = 56.6f;
I get this error message: :angry:
Error CS0589 in line 2 column 23, Internal compiler error during parsingSystem.FormatException: Input string was not in the correct format
Error in line -11 column 0, at System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x00000] in :0
Error in line -11 column 0, at System.Single.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x00000] in :0
Error in line -11 column 0, at Mono.CSharp.Tokenizer.adjust_real (TypeCode t, Location loc) [0x00000] in :0
Error in line -11 column 0, at Mono.CSharp.Tokenizer.is_number (Int32 c, Boolean dotLead) [0x00000] in :0
Error in line -11 column 0, at Mono.CSharp.Tokenizer.xtoken () [0x00000] in :0
Error in line -11 column 0, at Mono.CSharp.Tokenizer.token () [0x00000] in :0
Error in line -11 column 0, at Mono.CSharp.CSharpParser.yyparse (yyInput yyLex) [0x00000] in :0
Error in line -11 column 0, at Mono.CSharp.CSharpParser.parse () [0x00000] in :0
Program disabled, fix errors first.

If I write:
const float val = 56.6f;

Please Log in or Create an account to join the conversation.

7 years 11 months ago #722 by Xavier
Replied by Xavier on topic Need help with float
Reply to myself... :unsure:
A little dig on "Error CS0589" lead to the locale variable $LANG and my RPi defaults to this:
$ locale -a
C
C.UTF-8
POSIX
en_GB.utf8
fr_FR.utf8
 $ locale
LANG=fr_FR.UTF-8
LANGUAGE=
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=
So I did:
$ export LANG="en_GB.utf8"
$ locale
LANG=en_GB.utf8
LANGUAGE=
LC_CTYPE="en_GB.utf8"
LC_NUMERIC="en_GB.utf8"
LC_TIME="en_GB.utf8"
LC_COLLATE="en_GB.utf8"
LC_MONETARY="en_GB.utf8"
LC_MESSAGES="en_GB.utf8"
LC_PAPER="en_GB.utf8"
LC_NAME="en_GB.utf8"
LC_ADDRESS="en_GB.utf8"
LC_TELEPHONE="en_GB.utf8"
LC_MEASUREMENT="en_GB.utf8"
LC_IDENTIFICATION="en_GB.utf8"
LC_ALL=
Then when I run that simple automation prog in EasyIot:
const float val = 56.6f;

public void Setup () 
{
  Console.WriteLine ("Value={0:F2}",val);
}
I properly get:
Value=56.60
So the issue is closed. For me it's a bug in mono.

Please Log in or Create an account to join the conversation.

7 years 11 months ago #725 by skywatch
Replied by skywatch on topic Need help with float
Why do we need mono in the first place? Surely there is more than one way to skin a cat (as the saying goes)....

Please Log in or Create an account to join the conversation.

7 years 11 months ago - 7 years 11 months ago #726 by Xavier
Replied by Xavier on topic Need help with float
I'm not sure to understand...
We need it because EasyIot made the choice to develop on this framework. And I guess he did that because it's the shortest learning curve for him.

Now, Im trying to compile mono 3.12.0 from souces following This tutorial . The tar.bz2 is only 70MB but once exploded it makes 500MB :sick:

Please Log in or Create an account to join the conversation.

7 years 11 months ago #727 by Dennis
Replied by Dennis on topic Need help with float
thanks to mono, the code also runs on windows platforms.
And it is very convenient to code in c# and .NET.

regards

Please Log in or Create an account to join the conversation.

Time to create page: 0.483 seconds

Forum latest

  • No posts to display.