Results 1 to 5 of 5

Thread: [RESOLVED] [2.0] Float

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Resolved [RESOLVED] [2.0] Float

    Hi all
    Look that sub in the class

    C# Code:
    1. class cone
    2. {
    3.     float ht, rd;
    4.     public void set(float h, float r)
    5.     {
    6.         ht = h;
    7.         rd = r;
    8.     }
    9. }

    C# Code:
    1. cone c1;
    2. c1=new cone();
    3. c1.set(12.34,23.0);


    ERROR HERE c1.set(12.34,23.0);
    CAN NOT CONVERT DOUBLE TO FLOAT. WHY??
    Last edited by shakti5385; Apr 13th, 2007 at 03:32 AM. Reason: change vb code to c#

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Float

    "float" is an alias for Single. If you don't specify otherwise, any literal number with a decimal point in it is a Double. You cannot implicitly convert a Double to a Single because it is a narrowing conversion, i.e. data could be lost. If your method is expecting floats then you need to pass floats to it. To force a literal to type float you use an "F" suffix:
    C# Code:
    1. c1.set(12.34f, 23.0f);
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: [2.0] Float

    Quote Originally Posted by jmcilhinney
    "If your method is expecting floats then you need to pass floats to it. To force a literal to type float you use an "F" suffix
    Thanks sir
    It's working fine now.Can you give the list of more suffix in C# , that we have need to use in the code.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Float

    What did your last slave die of? Look it up on MSDN, as you should ALWAYS do first. I think I may have mentioned that once or twice. Someone will take notice one day.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up Re: [2.0] Float

    Quote Originally Posted by jmcilhinney
    Someone will take notice one day.
    Today

    Thanks sir

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width