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 /
This question was closed Oct 29, 2012 at 12:36 PM by AyJayKaySoft for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by AyJayKaySoft · Oct 29, 2012 at 12:07 PM · floatint

Are float values reliable?

Hey :) I want to use the coordinates of an object to read values in an array. Like:

 var vPosition : Vector3 = transform.position;
 var value = myArray[vPosition.x, vPosition.y, vPosition.z];

the positions are set by script and always able to be a int. I noticed that the float values sometimes goes like 0.99999999 or stuff. So do I have to set up an int Array or can I use the positions of the objects?

Comment
Add comment · Show 4
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 Fattie · Oct 29, 2012 at 12:13 PM 0
Share

right, that's normal on computers

check out $$anonymous$$athf.Approximately

avatar image AyJayKaySoft · Oct 29, 2012 at 12:26 PM 0
Share

so I have to use RoundToInt()... but than an extra int array for positions would work faster, right?

avatar image Fattie · Oct 29, 2012 at 12:30 PM 0
Share

you could use RoundToInt, or you could use an extra array

there is no performance concern either way

i personally would go with an additional "conceptual" array, yeah - for sure

if you essentially want them to be on a grid, use a "conceptual" integer array, express that in a data structure, or whatever - for sure

avatar image DannyB · Oct 29, 2012 at 12:33 PM 0
Share

If you are talking about having two arrays operate in parallel, I would advise against.

If ints suit your need, use it. If not, it is very normal to use floats and deal with their inaccuracies. Just do not rely on testing if float == float. Either use $$anonymous$$athf.Approximately() like @Fattie suggested or ask if float1 - float2 <= 0.01 or whatever is considered equal to you.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

11 People are following this question.

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

Related Questions

Display a float number when button is clicked 4 Answers

int conversion gives bad results ! 3 Answers

Convert positive float to negative? 5 Answers

How do i divide int by float? 1 Answer

Int vs. Float operations 4 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