Source for de.webdings.tools.CharToFloat

   1: /* CharToFloat.java - Copyright (c) 2005 by Stefan Thesing
   2:  <p>This file is part of Webdings Tools.</p>
   3:  <p>Webdings Tools is free software; you can redistribute it and/or modify
   4:  it under the terms of the GNU General Public License as published by
   5:  the Free Software Foundation; either version 2 of the License, or
   6:  (at your option) any later version.</p>
   7: <p>Webdings Tools is distributed in the hope that it will be useful,
   8: but WITHOUT ANY WARRANTY; without even the implied warranty of
   9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10: GNU General Public License for more details.</p>
  11: <p>You should have received a copy of the GNU General Public License
  12: along with Webdings Tools; if not, write to the<br>
  13: Free Software Foundation, Inc.,<br>
  14: 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA<br>
  15: */
  16: package de.webdings.tools;
  17: 
  18: 
  19: /**
  20:  * CharToFloat is used to convert textual representations
  21:  * of float numbers to the primitive data type float.
  22:  * 
  23:  * @author Stefan Thesing<br>
  24:  * Website: <a href="http://www.webdings.de">http://www.webdings.de</a>
  25:  * @version 1.0.1 10.08.2005
  26:  * 
  27:  */
  28: public class CharToFloat {
  29:     /**
  30:      * @param s A String representation of a float number
  31:      * @return float value of the represented number
  32:      */
  33:     public static float convert(String s) throws NumberFormatException
  34:     {
  35:         Float f = new Float(s);
  36:         return f.floatValue();
  37:     }
  38: 
  39:     /**
  40:      * @param c A char array representation of a float number
  41:      * @return float value of the represented number
  42:      */
  43:     public static float convert(char[] c) throws NumberFormatException
  44:     {
  45:        int i;
  46:        String s = new String();
  47:        for(i=0;i<c.length;++i)
  48:        {
  49:          s = s + c[i];
  50:        }
  51:        return convert(s);
  52:     }
  53:     
  54:     /**
  55:      * @param s StringBuffer representation of a float number
  56:      * @return float value of the represented number
  57:      */
  58:     public static float convert(StringBuffer s) throws NumberFormatException
  59:     {
  60:         return convert(new String(s));
  61:     }
  62:     
  63: }

© 2005 by Stefan Thesing;
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.