Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel formatting incorrectly

Status
Not open for further replies.

jjoy123123

Programmer
Oct 22, 2002
20
0
0
US
I'm trying to pass the value of varValue over to Excel. varValue is equal to 0.015 but Excel is reading it as 0.0149999996647239. The cell I'm populating in Excel is formatted as Number with 2 decimal places. Instead of showing .02, it is showing .01. Why is that?

Private Sub PopulateExcel(varValue As Variant)
oRange.Cells(1,2) = varValue
End Sub
 
Try:

oRange.Cells(1,2) = Format(varValue, "0.00")


Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
 
andy,

Declare your varValue as Double. It's probably declared as Single and does not have enough precision.

:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Or, of course, use a Currency.

Andy
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
"A computer program does what you tell it to do, not what you want it to do." -- Greer's Third Law
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top