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
2
Question by Tim Jansen · Mar 24, 2013 at 02:16 PM · floatinteger

Why is there sometimes an f behinf a number?

Hello, I'm following a few different tutorials on unity and scripting and i noticed that some put an f behind an integer or float when they are assigning it to a variable and I was wondering what the use of it is and why some people place an f and some don't.

Comment
Add comment · Show 3
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 Benproductions1 · Mar 25, 2013 at 06:26 AM 0
Share

$$anonymous$$ost things that work in C# work in Javascript. After all, they both compile down to the same thing. Please convert your comments to answers, as they do answer the question

avatar image AlucardJay · Mar 25, 2013 at 06:28 AM 0
Share

Ok, we've been told ;)

You are officially my 'Awesome dude of the day'

Edit : see, I knew there was a reason I made a comment on a technical question I didn't have the exact answer for, I cannot compete with a C# pro, and all-round pro Eric ..

avatar image Tim Jansen · Mar 25, 2013 at 04:04 PM 0
Share

Thnx everyone! I already knew a bit of the basics of js before starting with unity, but i had never seen the f before, but know i know why and what use it has. All answers are good answers in my opinion, but i just picked one to make sure that it is beeing showed as answered.

3 Replies

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

Answer by Eric5h5 · Mar 25, 2013 at 07:57 AM

Both Unityscript and C# use "f" to indicate a float and "d" to indicate a double. The difference is that double is the default for C#, but float is the default for Unityscript. So if you use a decimal number but leave off the "f" or "d", then it will use the default for whatever language you're using.

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
2

Answer by robertbu · Mar 24, 2013 at 02:52 PM

The 'f' is needed in C# because it has two different types of floating point numbers: float and double. C#'s default floating point type is double, but everything in Unity is a float, so the f is needed to force the compiler to treat a number like 3.286 as a float instead of a double.

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 AlucardJay · Mar 24, 2013 at 02:18 PM

The f is for a floating point number in C#. So you are seeing it in C#, and not in uJS. Make sure you know the difference between the two. Here's some links I found useful in converting between C# and JS. Read the first one especially, as they will explain the differences :

http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html

http://www.unifycommunity.com/wiki/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use?

http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/

Edit : decided that I would leave the 'double' explanation to a C# person =]

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
avatar image robertbu · Mar 24, 2013 at 03:57 PM 1
Share

@alucardj - C# that's me. I'm forever looking stuff up (or trying it out) when I answer questions with Javascript. Note I found out awhile back by accident that the 'f' suffix works in Javascript as well:

 function Start()
 {
     var f = 3.14159f;
     Debug.Log("f = "+f);
 }

It looks like Javascript/Unityscript has a 'd' for double and 'f' for float, but defaults to float.

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

13 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 avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Get integer or float value of a variable 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Material doesn't have a color property '_Color' 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