473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to round decimals in a simple manner

3
I need to round up with a program I'm supposed to develop that calculates the amount of money you need for a birthday party. The problem is, some of the things that need to be purchased come in a pack of so many. For instance, with the code below, 4/16 is going to be .25 (without the input of the variable that represents the amount of guests). Obviously, I can't buy .25 of something (in this case, a pack of napkins that come in 16). So, what would I do to round up and make the sum a whole number. Thanks!


NapNeeded = guests * 4
NapPack = NapNeeded / 16
if
NapPack is a decimal
round up
end if
NapCost = 4.00 * NapPack
Sep 28 '07 #1
3 1463
Savage
1,764 Expert 1GB
I need to round up with a program I'm supposed to develop that calculates the amount of money you need for a birthday party. The problem is, some of the things that need to be purchased come in a pack of so many. For instance, with the code below, 4/16 is going to be .25 (without the input of the variable that represents the amount of guests). Obviously, I can't buy .25 of something (in this case, a pack of napkins that come in 16). So, what would I do to round up and make the sum a whole number. Thanks!


NapNeeded = guests * 4
NapPack = NapNeeded / 16
if
NapPack is a decimal
round up
end if
NapCost = 4.00 * NapPack
just add an if clause before calculating NapPack:

If NapNeeded is a integer smaller then 16 make it 16,and then proceed.

Savage
Sep 28 '07 #2
Cage26
3
I follow. But how would I write that in code? I'm lost.
(Not to make you do that part of the work... but, I don't know how to write that)
Thanks!
Sep 28 '07 #3
mattmao
121 100+
You are using C or C++?

Use search engine:
http://www.thescripts.com/forum/thread134786.html

And this is from google search:
http://www.thinkage.ca/english/gcos/expl/c/lib/ceil.html

"ceil" returns the smallest integer (represented as a double precision number) that is greater than or equal to "x".

I hope this solves your question.
Sep 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Peter Scheurer | last post by:
Hi, we found some strange behavior when operating with floats and round(). The following simplified statement reproduces the problem. select 6.56 - round(convert(float, 6.56), 2) from...
3
by: shank | last post by:
I have the following equation. <% varWT = Round(CInt((rsFreePack.Fields.Item("Weight").Value)) + CInt(Session("w"))) %> Assume.... Round(CInt((rsFreePack.Fields.Item("Weight").Value)) = .12...
3
by: ORC | last post by:
Is there a round function that do a "Normal" rounding and not the round to nearest as the Math.Rounds is? Math.Round(3.44, 1); //Returns 3.4. Math.Round(3.45, 1); //Returns 3.4....
17
by: nomenklatura | last post by:
Hi, System.Math.Round function is confused me. for example i want to round 3.245 in with decimal symbol Result should be = 3.25 When i try to this in vb: A = 3.245 X = Round(A, 2) then...
4
by: Chris Davoli | last post by:
The folllowing will round to 526, but it should round to 527. It works correctly for all other numbers, except for this one. Does anybody know of a bug in Math.Round? Dim ldecWater As Decimal =...
36
by: Phat G5 (G3) | last post by:
Has anyone found a reliable way to force JS to round to a specific number of places? Every time I try I get different results. For example, I'd need to round 3.4589 to 2 places. What is the most...
2
by: Radek Cerny | last post by:
Hopefully I'm just missing something obvious, but this method (or more likely the CLR/complier) has a bug where I can not use the overloaded version: Round( double value, int digits ) It always...
4
by: =?Utf-8?B?UmVuZQ==?= | last post by:
Hello everyone I have a problem with Math.Round, it´s ocurring some strange: Math.Round(12.985) = 12.98, it´s wrong. It should be: 12.99 Why?? What is the problem? Help ME !!!!
13
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, I need to round a decimal value with a particular rule. For example: decimal a = 1.49m -1m decimal a = 1.5m -1m decimal a = 1.51m -2m I've tried Math.Round but with the value 1.5 it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.