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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change value of decimal

Status
Not open for further replies.

AlastairOz

Technical User
Jul 27, 2010
81
AU
I have a number field where I increment the field by + 1
or + 0.01 when adding records, depending on an option button selection.

When I switch to incrementing by + 1, I need to change the
numbers on the right hand side of the decimal point to .00
For example:

If I was incrementing by .01 and the value was 10.05,
and the increment option is changed to + 1 then the new
value needs be 11.00.

At this stage I get 11.05 instead of 11.00

Any ideas on clearing the .05 to .00 when selecting the
option button?
 
I am a little unclear when you say "Field" are you talking about a Table Field? or maybe a spinner control on a form or a textbox field?

Moving on from my confusion the example of 10.05 + 1.00 resulting in a 'wrong' 11.05 makes no sense 10.05 + 1.00 is 11.05 not 11.00. If you want 11.05 to be 11.00 look at the int(), Round(), floor() and Ceiling() functions.

Bottom line I think what you want is something like this:

Code:
&&-- Warning untested code!!!
If m.By_Integer
   m.Value = round( m.Value,0 ) + 1
Else
   m.Value = m.Value + 0.01
Endif

Lion Crest Software Services
Anthony L. Testi
President
 
"I need to change the
numbers on the right hand side of the decimal point to .00"


Change where?
* Change how the number(s) are being displayed in a Grid?
* Change how a number is being displayed in a Form Textbox?
* Change the field structure in the original data table?
* Where?

Good Luck,
JRB-Bldr

 
When you increment the field by + 1
Code:
REPLACE YourField WITH INT(YourField+1)

Testing displays the presence, not the absence of bugs.
If a software application has to be designed, it has to be designed correctly!
 
Thanks MrDataGuy,

The ROUND() function worked perfectly.
 
No, round does only work up to 10.5 (to stay with your example of 10, 10.01, ...), so if you ever have 50 .01 steps and do

ROUND(current+1,0) you don't get the next number, but one higher, as ROUND() does mathematical rounding, rounding .5 up, eg Round(10.5+1,0) is ROUND(11.5,0) results in 12, not 11.

You should either use INT(current+1) or better and simpler CEILING(current), eg CEILING(10.05) = 11 and CEILING(10.5) = 11.

If you never get as high as .5 in the decimal places that's OK, but it might bite you in several years from now.

Bye, Olaf.
 
Olaf makes a good point. You have to decide what something like 10.01 'translates' to if you want it to be 10 use the round() function if it should be 11 use the ceiling()

FYI:
Also realize that round ALLWAYS rounds up the half way point. e.g. round(10.5,0) = 11 and round (11.5,0) = 12 You may ask why is that a big deal? The answer is that if one is adding several or more numbers together the error keeps increasing. e.g. the total could be (Number of numbers ) * .5 off of the true total. What one wants is scientific rounding that is even numbers round down and odd numbers round up ( That is the half way point rounding) so that the errors cancel each other out. e.g. round(10.5,0 ) = 10. I doubt that this matters in your case thou.

Lion Crest Software Services
Anthony L. Testi
President
 
I thought about the rounding issue, but this form is a very specific form that uses the .01 for a count of items that would never normally exceed 2-3 items. At the most 6-7 in the extreme.
For the sake of correctness and future proofing I will try it another way. Like you said Olaf, "I might regret it later".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top