Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Ony · Jun 29, 2010 at 12:31 AM · floatxmlparselocalization

How to use System.Globalization.NumberFormatInfo for non US games?

We released a game the other day that uses XML files with floating point numbers in them for values in the game.

It's been reported to us that French users are not able to use the game unless they set their Region setting in Windows to be United States instead of France. The issue arises because in France (and other countries) they use a , as a decimal point instead of a period. When outr game tries to use a parseFloat on the numbers it crashes, unless they set their system to US mode.

So...

I saw something in here about using System.Globalization.NumberFormatInfo to account for computers with different systems, but I have no earthly idea how to use that.

Can someone point out a simple method of making this work?

Here's a typical line from my code:

listCharacters[charNum].body = parseFloat(reader.content);

What would I do to make this compliant with computers in other countries with a different system of reading floating point numbers?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Mike 3 · Jun 29, 2010 at 12:39 AM

you'd use something like this:

listCharacters[charNum].body = float.Parse(reader.content, System.Globalization.CultureInfo.InvariantCulture);

You could also store the culture info as a variable to cut down the code a little

e.g.

var ci = System.Globalization.CultureInfo.InvariantCulture;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Tetrad · Jun 29, 2010 at 12:40 AM

If the numbers are things you put in and not user-input strings, you should use the invariant culture to do all parsing.

Or to put it in code

float f = float.Parse(reader.content, System.Globalization.CultureInfo.InvariantCulture);
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Invalid Encoding Specification Xml 1 Answer

Parsing and displaying KML 0 Answers

Is pulling and parsing XML data from 3rd party API call possible? 1 Answer

How can I store data from an XML in lists 0 Answers

invalid format exception when parsing float 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges