I had post a thread on rounding before, but it really wasnt what I needed. I need quaterly rounding I have tried this
$FormatFinalTotal = (ceil($FinalTotal*20))/20;
and that rounds 67.67 to 67.70 or 23.23 to 23.25
what i need is 60.10 to 60.25 or 67.67 to 67.75
or 67.80 to 68.00
Any help would greatly be appreciated.
Thanks,
Alex
9 3587
Try this: -
$FormatFinalTotal = (round($FinalTotal*4))/4;
-
Its all just mathematics.
Try this: -
$FormatFinalTotal = (round($FinalTotal*4))/4;
-
Its all just mathematics.
You missed one thing though. It's ceil, not round.
And alexphd, you could have continued in the same thread rather then a new thread.
Hmmm, ceil or round depends on the intentions of the OP. It would be "round" if the OP wants to round the result to the nearest quarter, and "ceil" if the OP wants to round up to the nearest quarter.
Or?
Look at his requirements, you will come to know about his intentions.. 60.10 to 60.25 or 67.67 to 67.75 or 67.80 to 68.00
Look at his requirements, you will come to know about his intentions.. 60.10 to 60.25 or 67.67 to 67.75 or 67.80 to 68.00
I'm having a horrible case of Deja Vu
0_0
-Dan
both answered helped out a lot.
I have a question though how did you know to divide by 4 and multiply by 4?
Alex
both answered helped out a lot.
I have a question though how did you know to divide by 4 and multiply by 4?
Alex
It's an old mathematical trick. I learnt it at uni, but it is quite simple when you think about it! You can do it with normal rounding (use 2 instead of 4) etc...
Well, I never used this trick. It just came across my mind when someone in JavaScript forum asked me to round a number to the nearest hundredth.
ie. 5.867 to 5.87, 3.653 to 3.65
There's no second parameter in JavaScript like in PHP which could define the number of digits. So I told him to first multiply it with 100, then round it and then divide it with 100 again.
As far as the usage of the multiple (4 or 20) is concerned, inverse your interval, you will get the required multiple.
eg. if your interval is 0.05, multiple is 1/0.5 = 20
interval = 0.25, multiple = 1/0.25 = 4 (quarterly rounding case)
And as far as ceil and round are concerned, ceil will return the upper limit, and round will return the nearest limit, whether upper or lower. floor will return the lower limit always. - Number Ceil Floor Round
-
1.78 2 1 2
-
1.50 2 1 2
-
1.49 2 1 1
-
1.10 2 1 1
Regards,
Harpreet
Hi Alexphd,
why did I know to use the factor 4? It just came to me, really. The keyword was that you wanted to round to the nearest "quarter", and in order to use the functions floor(), ceil() or round() you need to remove the "decimal" portion of the number for the whole quarters. And to do this, you need to multiply the number by 4. Then any "quarter", i.e. 0.0, 0.25, 0.5 and 0.75, will become a whole number without decimal. Anything else can then be rounded, rounded up, or rounded down as wished. But then to get back to the original number again you need to reverse the scaling by 4, meaning you need to then divide by 4.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Norvin Laudon |
last post by:
Hi,
Can somebody explain the following, from the MSDN documentation for the
"System.Convert.ToInt32(double)" function
<quote>
Return Value
value rounded to the nearest 32-bit signed...
|
by: spebola |
last post by:
I am using vb.net 2003 professional and I get the following results
when using the round method:
dim Amount as decimal = 180.255
Amount = Amount.Round(Amount, 2)
Amount now contains 180.25. ...
|
by: Zorpiedoman |
last post by:
Howcome:
Dim D as decimal = .5D
msgbox d.Round(D, 0)
this returns "0"
Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!!
Documentation says this, but what the heck are...
|
by: Jiri Nemec |
last post by:
Hello all,
I have got one table with rounding values, table contains
prices and round types.
id price_from price_to rounding
1 0 1500 0.1
2 1500 ...
|
by: cj |
last post by:
Lets assume all calculations are done with decimal data types so things
are as precise as possible.
When it comes to the final rounding to cut a check to pay dividends for
example in VB rounding...
|
by: jdrott1 |
last post by:
i'm trying to round my currency string to end in 9. it's for a
pricing application.
this is the function i'm using to get the item in currency:
FormatCurrency(BoxCost, , , , TriState.True)
if...
|
by: md |
last post by:
Hi
Does any body know, how to round a double value with a specific number
of digits after the decimal points?
A function like this:
RoundMyDouble (double &value, short numberOfPrecisions)
...
|
by: jacob navia |
last post by:
Hi
"How can I round a number to x decimal places" ?
This question keeps appearing. I would propose the following
solution
#include <float.h>
#include <math.h>
|
by: bdsatish |
last post by:
The built-in function round( ) will always "round up", that is 1.5 is
rounded to 2.0 and 2.5 is rounded to 3.0.
If I want to round to the nearest even, that is
my_round(1.5) = 2 # As...
|
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,...
|
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$) {
}
...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |