# 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?
###### Who is Participating?

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.

Commented:
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
Commented:
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