• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

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?
0
logoncom
Asked:
logoncom
1 Solution
 
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
 
logoncomAuthor Commented:
works, thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now