Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 868607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:10:08+00:00 2026-05-15T10:10:08+00:00

Suppose option Strict On ; a and b – Integers Dim mySingle as Single

  • 0

Suppose option Strict On; a and b – Integers

Dim mySingle as Single = a / b  ' implicit conversion error

Solution A)

Dim mySingle as Single = CSng(a / b)  ' CSng

Solution B)

Dim mySingle as Single = a * 1F / b  ' x 1F

What solution is preferable?
What solution to take if performance is important?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:10:08+00:00Added an answer on May 15, 2026 at 10:10 am

    For readability and revealing intent, I would go with A:

    Dim mySingle as Single = CSng(a / b)  ' CSng
    

    Using A, you are clearly saying, I know the calculation returns a different type and that’s what I want.

    As for performance – I ran a quick micro-benchmark testing 1 million iterations for each and the difference was in the millisecond to sub-millisecond level, with a very slight advantage to CSing. Don’t worry about performance for this kind of conversions (of course, you need to test this on your own).

    Benchmark code:

    Sub Main()
        Dim mySingle As Single
        Dim a As Integer = 10
        Dim b As Integer = 5
    
        Dim iterations As Integer = 1000000
    
        Dim sw As New Stopwatch()
    
        sw.Start()
        For i As Integer = 1 To iterations
            mySingle = CSng(a / b)  ' CSng '
        Next
        sw.Stop()
    
        Console.WriteLine(String.Format("CSng(a / b) - {0}", sw.Elapsed))
    
    
        sw.Reset()
        sw.Start()
        For i As Integer = 1 To iterations
            mySingle = a * 1.0F / b  ' x 1F '
        Next
        sw.Stop()
    
        Console.WriteLine(String.Format(" a * 1.0F / b - {0}", sw.Elapsed))
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose a check constraint (involving multiple columns) with the not for replication option was
Suppose I have a dropdown (select tag) with 3 values. Our first option has
Suppose I have a form like this: Name:<input type=text name=xxx id=name/> Type:<select> <option>xx</option> <option>xx</option>
Suppose I have this: <select id=myselect> <option rel=a>1</option> <option rel=b>2</option> <select> How do I
Suppose we have an Option[String], and if there is Some(string) in there, we want
Suppose I have a dropdown select option like below: <form> <select name=option > <option
I am developing one application. Suppose user save question with 4 option and one
Let's suppose I have a <select> element: <select id=foobar name=foobar multiple=multiple> <option value=1>Foobar 1</option>
Suppose I have a menu option called 'Display' and my application com.android.display is performing
Suppose a webpage that presents a table, but with an option to download it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.