# Rounding to nearest 100 - Coldfusion - Advanced Techniques

Hi all. I am new to working with formatting numbers. I have a form inputting sales totals into a Microsoft Access database. I need a field for total sales and then another field for the total rounded to the nearest 100. I tried using the Round() function but it is just rounding to the nearest integer. Most of my numbers are in the thousands and need to be rounded to the nearest 100 (and possibly in the future the nearest 1000). For example, the total sales for one day is 2587. I would like this number rounded to be 2600. ...

1. ## Rounding to nearest 100

Hi all. I am new to working with formatting numbers. I have a form inputting
sales totals into a Microsoft Access database. I need a field for total sales
and then another field for the total rounded to the nearest 100. I tried using
the Round() function but it is just rounding to the nearest integer. Most of
my numbers are in the thousands and need to be rounded to the nearest 100 (and
possibly in the future the nearest 1000). For example, the total sales for one
day is 2587. I would like this number rounded to be 2600. I have set up
coding to format the number before it is inserted into the database. The
coding I have tried to use so far is <cfset RoundTOTAL = Round(#DTOTAL#)> where
"RoundTOTAL" will be my rounded sales total and "DTOTAL" is the daily total
sales. When "DTOTAL" equals 2587 the "RoundTOTAL" in the database is
displaying as 2587. I assume I need to add something to my Round funtion but
am unsure of what. Any help would be greatly appreciated!!!

ccnorris Guest

2. ## Re: Rounding to nearest 100

You have to multiply or divide it by multiples of ten then round it then
reverse the multiplication or division. Like so:

<!--- set initial value --->
<cfset myValue = 2587>

<!--- round to the nearest hundred --->
<cfset newValue = Round(myValue / 100) * 100>

<cfoutput>#newValue #</cfoutput>

Stressed_Simon Guest

3. ## Re: Rounding to nearest 100

Simon,

Thank you so much for you help! It works great! :)

Thanks again,
Carolyn
ccnorris Guest

4. ## Re: Rounding to nearest 100

Hi again. If you don't mind I need a little more information.

For my initial question I asked about rounding to the nearest 100. I have now
created a new form to input support numbers. Most are coming in with totals
with two integers (ie, 35). For this section I assume I am going to set the
round to the nearest 10. However, what If I get a total in that exceeds the 2
digits and is in the 100s? I think I need a way to round to the nearest 10 OR
nearest 100 depending on the data. In this case do I need to set up if
statements?

Thanks in advance for any help!

ccnorris Guest

5. ## Re: Rounding to nearest 100

Thank you that is very flatering.

For what you are trying to achieve you will need to use if statements. You'll
have to check the range of the current value amd the format the numbers
accordingly. If you need help with that then please post agina and we'll see
what we can do.

Stressed_Simon Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•