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 Dec 30, 2014 at 09:18 AM by Landern for the following reason:

The question is answered, right answer was accepted

This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Daniel Greenhorn · Dec 24, 2014 at 08:15 AM · vector3floatprecisiondoubledecimal

Convert double to float for Vector3

I get a "Cannot implicitly convert 'double' to 'float'. An explicit conversion exists (are you missing a cast?)" message for

the following formula to be used as argument in a Vector3:

float sph_x = Input.mousePosition.x/1280*7.7-3.85f; //sph_x would be 0,22859374999999900000

Surprisingly it works for this formula : float sph_x = Input.mousePosition.x/1280*7-3.85f; //sph_x would be -0,14218750000000000000

I need only 2 or 3 decimals of precision. Is there no conversion from double to float? I found only the Mathf.RoundToInt.

Not even if I multiply by 1000, Round to int and then divide back by 1000 doesn't get a float:

float sph_y = ( Mathf.RoundToInt (1000* (Input.mousePosition.x/1280*7.65-3.85f) ) )/1000;

Now it gets 2 errors: the "cannot implicitly ..." and another one "best overloaded method..." Dividing an integer by 1000 results in 3 decimals ONLY so a float should be OK.

Only it isn't.

There has to be a nice simple way to do this...

Thanks.

Comment
Add comment · Show 1
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 Daniel Greenhorn · Dec 25, 2014 at 06:20 AM 0
Share

Thanks, Owen and Paulius. What can I say? There really should be a delete button for this question

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by Paulius-Liekis · Dec 24, 2014 at 12:52 PM

7.7 needs an f in the end.

Otherwise you can always do this, i.e. add explicit cast just as error tells you too:

 float sph_x = (float)(Input.mousePosition.x/1280*7.7-3.85f); 
Comment
Add comment · Show 1 · 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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Vector3 using Doubles Instead of Floats 2 Answers

C# CS0266 error for multiplying by a decimal 1 Answer

Convert float in Transform to double 1 Answer

On the accuracy of floats and doubles: Where/when do rounding errors usually occur, and how can I avoid them? 1 Answer

More Vector3 decimal precision in the Console? 3 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