How to drop decimal when value is zero

  • Thread starter Thread starter Kim Smith
  • Start date Start date
K

Kim Smith

My question is that I have set my text box in a report to just give me one
decimal,
but how do I set it to drop the decimal when the value is 0.


example:


Change 3.40 to 3.4 but change 3.0 to 3


Just by setting decimal places to auto in text box properties I get all (.5)
to work its just when you do numbers like 3.2 and 3.6 that you get 3.20 and
3.60.

To recap if I have a row of numbers I would like:

3.2 -> to read as 3.2 not 3.20

3 -> to read as 3 not 3.0

2.2 -> to read as 2.2 not 2.20

4.5 -> to read as 4.5 not 4.50

Thanks
 
this works, but where there is just a whole number like 3, I want it to
return a 3 not a 3.0.
 
Sorry, Kim, I don't know that it can be done. Maybe somebody has a cute trick
to make that happen. I tried some things, but mostly get errors.
 
if the Data Type of the field, in the report's underlying table, is Number,
with Field Size of Single or Double, then you should just be able to set the
bound textbox control's DecimalPlaces property to 1, and leave the Format
property blank. since a field with number data type won't save a leading or
trailing zero in the field value, the handling should be automatic. at
least, that worked for me when i tested it. but if it doesn't work for you,
on a value with a Number data type, try the following:

add an unbound textbox control to the report, which i'll call Text6. in the
report section's Print event procedure, add the following code, as

If Int(Me!FieldName) = Me!FieldName Then
Me!Text6 = Format(Me!FieldName, "#0")
Else
Me!Text6 = Format(Me!FieldName, "#0.0#")
End If

if the Data Type of the field is Text, add the unbound Text6 as noted above,
and try this code instead in the report section's Print event procedure, as

On Error Resume Next

Dim dbl As Double
dbl = CDbl(Me!FieldName)

If Int(dbl) = dbl Then
Me!Text6 = Format(Me!FieldName, "#0")
Else
Me!Text6 = Format(Me!FieldName, "#0.0#")
End If

in either case, replace "FieldName" with the correct name of the field in
the report's RecordSource. if you don't know how to create an event
procedure, see "Create a VBA event procedure" at
http://home.att.net/~california.db/downloads.html for illustrated
instructions.

hth
 
Back
Top