Rounding minutes to nearest five.

Hi,
I have tried the various methods suggested on other forum messages but to no avail.
I have a GUI that acts as the client for a reminder system i am making for some coursework.
It contains a combo box with values for the user to select a time from, however the time is not displayed in the format i would like it to be.
I would like the current time from the instance of calendar i have created to be rounded to the nearest five up.
The code i have for the combo box at the moment is:
     cal.set(cal.MINUTE, (int)Math.round((double)cal.MINUTE));
          n=0;
          int z = 0;
          while(z<288)
               cal.add( cal.MINUTE, n);
               s = DateFormat.getTimeInstance(DateFormat.SHORT).format(cal.getTime());
               time_cb.addItem(s);
               n=5;
               z++;
This code always sets the first value of the combo box to 10 minutes past the hour and increments it by five from there. This happened with all the other methods i tried from the other forums also.
I would like it to round to the nearest five the current time and increment by five from this time.
Thanks for your time and help.

Hi,
I have tried the various methods suggested on other
forum messages but to no avail.
I have a GUI that acts as the client for a reminder
system i am making for some coursework.
It contains a combo box with values for the user to
select a time from, however the time is not displayed
in the format i would like it to be.
I would like the current time from the instance of
calendar i have created to be rounded to the nearest
five up.
The code i have for the combo box at the moment is:
Your first line is wrong. Your setting the calendar minutes field to
some random value, cal.MINUTE, which has nothing to do with the current minute. You need to do
Calendar c = new GregorianCalendar()
which automatically sets the current minute
cal.set(cal.MINUTE,
(int)Math.round((double)cal.MINUTE));
          n=0;
          int z = 0;
          while(z<288)
               cal.add( cal.MINUTE, n);
s =
=
DateFormat.getTimeInstance(DateFormat.SHORT).format(ca
.getTime());
               time_cb.addItem(s);
               n=5;
               z++;
This code always sets the first value of the combo box
to 10 minutes past the hour and increments it by five
from there. This happened with all the other methods i
tried from the other forums also.
I would like it to round to the nearest five the
current time and increment by five from this time.
Thanks for your time and help.

Similar Messages

  • Rounding Time to nearest 30 minutes

    Good day,
    I'm looking for a way to round the time portion of a date value. My query needs to return the time of day, rounded to the nearest 30 minutes - top of the hour or bottom of the hour.
    If sysdate is: 12/28/2009 11:08:19 AM
    I need to see: 12/28/2009 11:00:00 AM
    If sysdate returns: 12/28/2009 11:18:19 AM
    I need to see: 12/28/2009 11:30:00 AM
    Any help is appreciated.
    Regards,
    Gary F.

    Aketi Jyuuzou wrote:
    I like case expression B-)Me too, but I like then simple B-) :
    with dates as ( -- generating sample data
    select to_date('12/28/2009 11:08:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
    select to_date('12/28/2009 11:18:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
    select to_date('12/28/2009 11:38:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
    select to_date('12/28/2009 11:48:19', 'mm/dd/yyyy hh:mi:ss') from dual)
    select dt,
    case when to_char(dt,'mi') >= '45'
         then trunc(dt,'hh') + interVal '60' minute
         when to_char(dt,'mi') >= '15'
         then trunc(dt,'hh') + interVal '30' minute
         else trunc(dt,'hh')
         end as new
      from dates
    DT                  NEW
    2009-12-28 11:08:19 2009-12-28 11:00:00
    2009-12-28 11:18:19 2009-12-28 11:30:00
    2009-12-28 11:38:19 2009-12-28 11:30:00
    2009-12-28 11:48:19 2009-12-28 12:00:00
    SQL> SY.

  • Rounding time to nearest hourly quarter

    I have several records like
    2/19/2010 1:25:46.000000 PM
    2/19/2010 1:40:46.000000 PM
    2/19/2010 1:55:46.000000 PM
    2/19/2010 2:10:46.000000 PM
    I want to round them off to the nearest quarter like
    2/19/2010 1:30:00.000000 PM
    2/19/2010 1:45:00.000000 PM
    2/19/2010 2:00:00.000000 PM
    2/19/2010 2:15:00.000000 PM
    Any ideas how I would do that? a trunc(col,'mi) only lets me round it to the minute..
    Note that records are not necessarily in the 5 minute interval difference it can also be 7 minute difference or 4 minute difference from the nearest quarter...
    so I can also have records like
    SysUpTime     2/19/2010 10:31:00 PM
    SysUpTime     2/19/2010 10:57:00 PM
    SysUpTime     2/19/2010 11:31:00 PM
    etc.
    Edited by: zebango on Mar 9, 2010 4:16 PM

    Solomon Yakobson wrote:
    But OP asked for "*Rounding* time to nearest hourly quarter". Same applies to Aketi's solution which, BTW, which always bumps it up to next 5 min.In which case, just substitute "Round" for "Floor"!
    Although thinking about it, you'd probably want to add seconds into the mix:
    with table_x as (select to_timestamp('11/03/2010 11:45:39', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 11:52:29', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 11:52:30', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 11:52:31', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 12:00:01', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 12:07:29', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 12:07:31', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 13:22:10', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 13:22:40', 'dd/mm/yyyy hh24:mi:ss') t from dual)
    select t,
           trunc(t, 'hh') + ROUND((to_char(t, 'mi') + (to_char(t, 'ss')/60))/15)*15/1440 nearest_15_min
    from   table_x
    T                                NEAREST_15_MIN      
    11/03/2010 11:45:39.000000       11/03/2010 11:45:00 
    11/03/2010 11:52:29.000000       11/03/2010 11:45:00 
    11/03/2010 11:52:30.000000       11/03/2010 12:00:00 
    11/03/2010 11:52:31.000000       11/03/2010 12:00:00 
    11/03/2010 12:00:01.000000       11/03/2010 12:00:00 
    11/03/2010 12:07:29.000000       11/03/2010 12:00:00 
    11/03/2010 12:07:31.000000       11/03/2010 12:15:00 
    11/03/2010 13:22:10.000000       11/03/2010 13:15:00 
    11/03/2010 13:22:40.000000       11/03/2010 13:30:00 

  • Rounding off to nearest whole number without condition

    hi,
    i want to round a real number to an integer value,,wihout any conditions like
    10.01 should be 11
    10.1 should be 11 and like that
    is it posible to do it?
    thanks in advance.
    amit

    It doesn't look like you are trying to round to the nearest whole number here. It looks like you are trying to find the smallest integer value that is greater than or equal to the real number. If so, you would want to use the CEIL function (i.e.
      1  SELECT CEIL(10.01)
      2*   FROM dual
    SCOTT @ hp92 Local> /
    CEIL(10.01)
             11Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Formulae - rounding down to the nearest five

    I am new to JAVA programming and not (yet) a brilliant mathematician. Can anybody tell me an algebra formula for rounding down to the nearest 5 (in 100)? Thanks in advance [email protected]

    Your question is not very clear.
    Still I think this would help
    //begin
    int remainder = number % 5 ;
    //We get the remainder
    number = number - remainder;
    //Trim down to the lower value
    if (remainder >= 3){
    number = number + 5 ;
    //If the remainder is 3 or more we should round to the higher value
    //End of block
    Hope this helps
    Shubhrajit

  • Datepiker rounding seconds to nearest minute in presentation?

    Hi all,
    I have a presentation with a display-only, non-editable datepiker, that references an object variable of type Time.
    The variable contains a full timestamp with date and time down to microseconds; however when the time gets displayed in my presentation, the seconds are always rounded to 00.
    Has anyone encountered this or know how to deal with it?
    Thanks!
    B

    Hi all,
    I have a presentation with a display-only, non-editable datepiker, that references an object variable of type Time.
    The variable contains a full timestamp with date and time down to microseconds; however when the time gets displayed in my presentation, the seconds are always rounded to 00.
    Has anyone encountered this or know how to deal with it?
    Thanks!
    B

  • Data usage rounded up to nearest GB in Bill summary; Cannot download details as spreadsheet

    Two problems:
    1. Bill summary misrepresents data usage, rounding up to the nearest GB, for one of our 4 lines.
    2. Data detail "download to spreadsheet" does not work.
    My account has 4 lines. I have an old Family Share plan (no longer available) for 700 minutes; a "feature" for unlimited text; and individual data plans for each of the 4 lines. My daughter has a 2 GB data plan.
    Latest Verizon Wireless bill says my daughter used 1.0000000 GB of data. She didn't think so. I logged in to Verizon, went to "View Bill". then for the Bill Period: May 29, 2014 - June 28, 2014, I selected "Details for" > "DATA". I see all the usage by date and time; I can adjust the display from default "KB" to "MB". Then I clicked the link "Download to SpreadSheet ".
    Unfortunately, I get a file with only one line, just the headers, no data:
    "Date"    "Time"    "Usage Type"    "Description"    "Minutes"    "Application Price"    "Total"
    As a workaround, I can select and copy the data on the web page, then paste it into a spreadsheet program. I added a "sum()" formula and found that she used only 325 MB, not 2 GB.

    Does the bill say she used 1 GB or 2 GB? You had mentioned them both.
    As far as the usage, it's not too say she literally used that much but to say that she used that much or less. It may not matter since she has the 2 GB/$30 which means that you would be billed the same way either way.
    Your inability to download the spreadsheet may be due to an issue with your browser.

  • Rounding off to nearest value with formatNumber

    Can I use the formatNumber tag to round my numeric value to the nearest value?
    Like if it's 15.7 I would like to display 16
    And if it's 15.2, I would like to display 15
    I could successfully truncate by giving a patteren but Im not sure if I can round it off.
    Regards,
    Leena

    Yes you can - the following works on JSTL 1.1 / Tomcat 5.5 :
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <html>
    <head><title></title></head>
    <body>
    Test Auto Rounding of 16.8 :
    <fmt:formatNumber value="16.88" pattern="##"/>
    <br/><br/>
    Test Auto Rounding of 16.2 :
    <fmt:formatNumber value="16.22" pattern="##"/>
    </body>
    </html>Message was edited by:
    appy77

  • Rounding off to nearest decimal point

    i have these values
    35.2
    35.3
    35.4
    35.5
    35.7
    35.8
    35.9
    36.0
    i am looking for indexes closet 35.74 in my array. (which is index 4.)
    i used the "round to nearest" function and it gave me 36.
    which is index 7.
    what other ways to get the right index?
    Solved!
    Go to Solution.

    You will always have some difficulties with rounding to a specific number of digits after the decimal point because of the way numbers are represented in binary. When expressed in binary 0.1 is an infinitely repeating expression. Regardless of the display the internal representation of the number always uses the maximum resolution for the data type (8 bytes for DBL).
    So you need to be very careful to define exactly what you  want. If you have an array of values (regardless of the way they are displayed) Then you can find the closest to a Test Value by subtracting Test Value from the array and finding the minimum of the absolute values of the differences.
    Note that in the image below the same values are in Array and Array 2 with the display on Array 2 set for 20 siginficant digits. 
    Lynn

  • Always round up to nearest whole in APO DP

    Hi
    there is a requirement to always round up data to nearest whole number. number should be always rounded above and not rounded down.
    Example a value of 0.07 should be rounded to 1
    a value of 1.25 should be rounded to 2
    a value of 1.75 should be rounded to 2
    a value of 1.07 should be rounded to 2
    and so on
    Is there a way i can achieve in APO DP by some settings/paramater/config/macro/exit etc etc - i am on SCM 7.0
    Thanks,
    TJ

    Tejinder
    Try using the CEIL() function in a macro.
    Rishi Menon

  • SQL for rounding to the nearest value

    Hi All,
    My Oracle DB version is 10g Release2 and also 11gR1
    I have data like below, I need to write a SQL for the below requirement.
    ID   RANGE_LOW                RANGE_HIGH
    1      50                    55             
    2      55                    60
    3      60                    63 
    4      63                    77 
    5      77                    84   The requirement is like I need to check a value between the above range low and high then round it to the nearest value.
    Say, for example if I have 68 then the value is rounded to 63 else if 74 then 77 else if its in the middle of two values (70) then rounded to the highest value, here its 77.
    Please advice.

    Ashu_Neo wrote:
    hi Purvesh,
    I think , you didn't check it properly with requirement of posting. Your query needs to be changed a bit. Please verify againYes, I probably missed or overlooked the last line.
    Here is the updated solution then:
    with data as
      select 1 id, 50 low, 55 high from dual union all
      select 2, 55, 60 from dual union all
      select 3, 60, 63 from dual union all
      select 4, 63, 77 from dual union all
      select 5, 77, 84 from dual 
    chk_val as
      select &val val from dual
    select id, low, high,
           val input_value,
           case
            when val < (low + high)/2
              then low
            else
              high
           end round_value
      from data, chk_val
    where val between low and high;
    ID                     LOW                    HIGH                   INPUT_VALUE            ROUND_VALUE           
    4                      63                     77                     70                     77

  • Connection goes on for five minutes / off for five minutes

    I connected a new Airport Express today. Using Safari or Firefox, I have five great minutes with no problems whatsoever, then five minutes off. But the interesting fact is, iChat and Mail keep on working. It's just the browser. I tried with and w/out OpenDNS, and it's the same. Sometimes Mail stops as well, but iChat or Skype are always connected... Help!

    One interesting thing to mention is that, when I run the diagnostics, all the lights are green and it says it appears to be working properly... but I can't surf the web.

  • Rounding minutes up or down when using a to_char function

    Hi, this is my query: select (to_char(incident_date, 'HH24:MI')) Time from cla_event
    Incident_Date column has a date and time in it. The above query pulls the time which is what I require. I do however want the hour to be rounded down if less than 30min and up if grater than 30min. For example 21:29 becomes 21:00 and 21:37 becomes 22:00.
    This is just a single column in my query so I'm hoping for a simple solution if there is one.
    Thanks!!!
    Banner:
    Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE     11.2.0.2.0     Production"
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    WITH
         t_data AS
              select '21:29' as col1 from dual union all
              select '21:32' from dual
    SELECT
         col1,
         CASE
              WHEN SUBSTR(col1,                      -2) >= 30
              THEN
                   TO_CHAR((to_date(col1, 'HH24:MI'))+1/24,'HH24')||':00'               
              ELSE
                   TO_CHAR((to_date(col1, 'HH24:MI')),'HH24')||':00'
         END new_val,
         TO_CHAR(ROUND((to_date(col1, 'HH24:MI')),'hh24'),'HH24:MI') as new_val2
    FROM
         t_data;
    COL1  NEW_VAL NEW_VAL2
    21:29 21:00   21:00   
    21:32 22:00   22:00 Edited by: bpat on Oct 20, 2011 11:49 AM
    Added Rafu's solution too

  • Rounding up to nearest whole number question

    I have a calculation script that sometimes returns a decimal result. How would I create a script that would round that decimal up to the next whole number? Anyone have any idea's?

    okay, I am not very good with this. That command is new to me. Where would I place that script if I already have a javascript script in the calculate event of that numeric field I am trying to get rounded up?
    I basically have the javascript code in the numeric fields calculate event set to
    this.rawValue = subform1.numericField1.rawValue;
    I tried putting your script on the change event hoping I could use formCalc there but get a error when testing saying Ceil is not defined. Thanks

  • Rounding to the nearest thousand

    hi
    does anybody know how to ceil and floor an integer to the nearest thousand?
    thanks in advance?

    hi friend,
    try this code, it may help you.....
    public class NT {
        /** Creates a new instance of NT */
        public NT() {
        public int roundByThousands(int val)
            int retval=0;
            for(int i=0;i<val;i=i+1000)
                int k=val-i;
                if(k<1000)
                    if(k<=500)
                        retval=val-k;
                    else
                        retval=(1000-k)+val;
            return retval;
        public static void main(String args[])
            NT nt=new NT();
            System.out.println(nt.roundByThousands(11502));
    }

Maybe you are looking for