Re: Formating dates & numbers

"Kris Ardis" <Kristopher.Ardis-6tN4nzCoH/[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.tini
Message-ID <007e01c3fd44$e055f900$764000b4@kardis>
> Another option I explored was using a substr but I kept getting
> errors on dereferencing a double so I thought this would be the best
avenue.

Please see 'Limitations.txt' on the imprecision of converting floating point
to string to TINI.  The numbers themselves are fine, but the conversion to
strings is prone to these kinds of errors.  You should be able to do a
substring, but it sounds like you are trying to do...
    System.out.println("Value: "+somedouble.substring(...));

Try instead to create a String out of the double first...
   String double_as_string = Double.toString(somedouble);
   /* probably want to check first to see how many digits are after decimal
place ... */
   double_as_string = double_as_string.substring(0,
double_as_string.indexOf('.')+3);
   System.out.println("Value: "+double_as_string);

> Calendar calendar = new GregorianCalendar();
> Date today = new Date();
> calendar.setTime(today);

You can replace these 3 lines with...
     Calendar calendar = new GregorianCalendar();
which creates a calendar object with the current locale, time zone, and
current time.  This should cut down on your processing time here
significantly.

> String timeLCD =
> calendar.get(Calendar.YEAR) + "-" +
> ((calendar.get(Calendar.MONTH)<10)?"0":"") + calendar.get(Calendar.MONTH)
+
> "-" +
> ((calendar.get(Calendar.DAY_OF_MONTH)<10)?"0":"") +
> calendar.get(Calendar.DAY_OF_MONTH) + " " +
> calendar.get(Calendar.HOUR) + ":" +
> ((calendar.get(Calendar.MINUTE)<10)?"0":"") +
calendar.get(Calendar.MINUTE)
> + " " +
> ((calendar.get(Calendar.AM_PM)==1)?"PM":"AM");
>

If you want to cut down more time here, create a byte array and fill it in
with what you want the string to look like, then create your string from
that byte array.  String creation/manipulation is painful for both memory
management and processing time.

See chapter 11 of the TINI Specification for more information on performance
tuning apps (http://www.maxim-ic.com/products/tini/devguide.cfm)

Kris


Kris



_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.