Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by youngapprentice · Aug 20, 2012 at 07:46 PM · javascriptfloatparse

Float.Parse() Question (Quickie)

Hello, all! I have a string like this:

"0.123"

and I used:

 Debug.Log(float.Parse(MyString));

On it and got an output of 0.1 as opposed to the entire float. What's going on? Am I using an improper function?

Thanks!- YA

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

1 Reply

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

Answer by Bunny83 · Aug 20, 2012 at 07:54 PM

I'm not sure what you're doing wrong. When i use:

 Debug.Log(float.Parse("0.123"));

Unity prints : "0.123"

Maybe you talk about the values in a struct like Vector3? Unity rounds the values when you convert them to a string, but the actual value is correct.

Comment
Add comment · Show 6 · 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 youngapprentice · Aug 20, 2012 at 08:02 PM 0
Share

$$anonymous$$aybe I should give you more info. Firstly, it is actually several floats like this : "0.1234.3245.324" Each having 4 decimal places. So it is actually Debug.Log(float.Parse($$anonymous$$yString.Substring(0,5)));

Which now gives me:

0.22

What's up?

And also, I A$$anonymous$$ converting to string at some point. Is there a way I can prevent rounding to a certain point?

Thanks for the help! - YA

avatar image youngapprentice · Aug 20, 2012 at 08:11 PM 0
Share

I think I have figures it out. I am debug.logg'ing a COLOR. Wow. I'm a little embarrassed over here. Well thanks for the help!- YA

avatar image Bunny83 · Aug 20, 2012 at 10:19 PM 0
Share

Is there really no seperator between your 3 values? How can you tell where a number starts and where it ends? What is a value has two digits before the decimal point?

avatar image youngapprentice · Aug 21, 2012 at 12:06 AM 0
Share

Ah well I borrowed a color picker code from the community and have it in game. I made my own picker in photoshop and when I debugged the code, it exported R,G,B, and A floats that were all in a format of:

X.XXX

Will it not always be this way? I can easily right code to have a separator there.

avatar image youngapprentice · Aug 21, 2012 at 12:06 AM 0
Share

In fact that would make my job a lot easier

Show more comments

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Converting a .CSV string array to a float array 1 Answer

Cannot convert 'String' to 'float (but im actualy converting a float to a string) 2 Answers

Insert a semicolon at the end Error. (JavaScript) 1 Answer

I need help with the eval() function of javascrit 1 Answer

Saving Object Position in Float NOT Object 1 Answer


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