Search Unity

How to float

Discussion in 'Scripting' started by Nightshade1, Apr 1, 2012.

  1. Nightshade1

    Nightshade1

    Joined:
    Feb 6, 2011
    Posts:
    95
    I looked up float variables and i didnt understand at all can i use it to represent numbers?
    and how would i use it?
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I've never been able to float. They told me in swimming class that I wasn't calm enough. I'm pretty heavy for my size, so I think it might actually be a bone density thing (I've never had a fracture), which will be helpful as I age.

    Seriously though, go read or watch any tutorial. Come back with questions if you need to.
     
  3. Posly

    Posly

    Joined:
    Jan 14, 2012
    Posts:
    151
    There's two ways to store numbers, using an int and using a float. Both of them are just numbers, 5, 7, 6.5, 4... but the difference in between them is that an int is a whole number, 5, 3, 4, 8... but a float is a number that can hold a decimal, 5.3495, 5.0, 53.7... They both have different uses, if you have trouble deciding which one to use, use a float by default.
     
  4. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    There are far more than two ways, but your point still holds.
     
  5. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    heh, for the level of this thread, I feel it is more than enough information ;)
     
  6. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Last edited: Apr 2, 2012
  7. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    What?
     
  8. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    I agree with you : p
    Float and int are both 32-bit. Confused it with double : )
     
  9. Nightshade1

    Nightshade1

    Joined:
    Feb 6, 2011
    Posts:
    95
    How woulkd i use this
    Can i use and make equations
     
  10. Judgerknot

    Judgerknot

    Joined:
    Feb 13, 2011
    Posts:
    45
    Code (csharp):
    1.  
    2. float a = 0.25f;
    3. float b = 3.62f;
    4.  
    5. Debug.Log(a + b);
    6.  
    7.  
    Is that what you are looking for?
     
  11. meth0s_

    meth0s_

    Joined:
    Dec 11, 2011
    Posts:
    60
    I have written a small and simple math example using an int, a short, and float expression's giving a float result. this should give you some understanding of how they can be used.
    Code (csharp):
    1. using System;
    2. class MixedTypes
    3. {
    4.    public static void Main()
    5.    {
    6.       int x = 3;
    7.       float y = 4.5f;
    8.       short z = 5;
    9.       Console.WriteLine("The result is {0}", x*y/z);
    10.    }
    11. }
    12.  
    and yes the answer is 2.7 if you try this feel free to do so

    if you need any more help wth this feel free to ask ok

    edited part : a float will hold decimal places ie. 1.3245
     
    Last edited: Apr 3, 2012