Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7481

Re: number conversion

From Roedy Green <see_website@mindprod.com.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: number conversion
Date 2011-08-29 14:17 -0700
Organization Canadian Mind Products
Message-ID <7vvn579ofl9apf3lm9ukp7cg9odntc8h1p@4ax.com> (permalink)
References <948475fb-b1da-4062-8008-c64a4ea4206b@x21g2000prd.googlegroups.com>

Show all headers | View raw


On Mon, 29 Aug 2011 11:01:44 -0700 (PDT), mamta81
<roy.mamta@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>2) Is there any other way to find the number of digits before and
>after decimal?

Your code could be simplified by using

final int place = s.indexof( '.' );

n is traditionally a count, not a String.  This dates back to FORTRAN
days.

Since the number you are looking at is expressed in binary, it really
does not have a number of decimal places.  You can choose any number
of places  you please in the string representation if you use
DecimalFormat. You are just measuring an artifact of Java's default
double -> String conversion method.
See http://mindprod.com/applet/converter.html

For some completely different techniques see:
http://mindprod.com/jgloss/widthindigits.html
http://mindprod.com/jgloss/log.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
The modern conservative is engaged in one of man's oldest exercises in moral philosophy; that is, 
the search for a superior moral justification for selfishness.
~ John Kenneth Galbraith (born: 1908-10-15 died: 2006-04-29 at age: 97) 

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

number conversion mamta81 <roy.mamta@gmail.com> - 2011-08-29 11:01 -0700
  Re: number conversion Screamin Lord Byron <scre@min.dot> - 2011-08-29 21:35 +0200
  Re: number conversion Roedy Green <see_website@mindprod.com.invalid> - 2011-08-29 14:08 -0700
    Re: number conversion Lew <lewbloch@gmail.com> - 2011-08-29 14:17 -0700
      Re: number conversion Roedy Green <see_website@mindprod.com.invalid> - 2011-08-29 14:52 -0700
  Re: number conversion Roedy Green <see_website@mindprod.com.invalid> - 2011-08-29 14:17 -0700

csiph-web