Converting a number to an Integer or a Double based on number after the decimal

I have a program that populates data onto an excel sheet.  I have the data in my SQL 2005 DB as a Numeric(8,2) datatype.

When I pull the data to populate the excel sheet, I want to either insert the number with a decimal or no decimal depending on the value.

So if the value is "4.00" I want to insert "4" to the excel sheet.  If the value is "4.25" I want to insert "4.25" to the excel sheet.

How do i do that?
logoncomAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul_Harris_FusionCommented:
Hi

If you insert it as a number then Excel will always store it as decimal number behind the scenes.  You could store it as a string but I suspect that would not be the right option since Excel arithmentic would not work.

Which leaves the column formatting in the excel sheet.  If you use Excel General formatting then you should get the results you want.  If you use Number that you will always get the number of decimal places specified on the format.

Hope this helps
If you want to inser

Not much of a solution this
0
Christopher KileCommented:
Do you want to simply display this, or post an integer to the sheet?  Because, by default, Excel displays 4.0 as 4.
Otherwise, if you are willing to send strings to Excel,
Dim realVal as Double
Dim outputString as String
If realVal = System.Math.Floor(realVal) Then
    outputString = Cint(realVal).ToString
Else
    outputString = realVal.ToString
End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
logoncomAuthor Commented:
works, thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.