hunterb100's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Active Members
Active Posts:
144 (0.14 per day)
Joined:
29-August 11
Profile Views:
924
Last Active:
User is offline Jul 13 2014 02:51 PM
Currently:
Offline

Previous Fields

Country:
CA
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
AMD
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   hunterb100 Currently writing software to replace iTunes for sound-tech-ing. Just playback functions, but many more advanced features and everything in one place.

Posts I've Made

  1. In Topic: Accurately converting units involving extremely small numers?

    Posted 9 Jul 2014

    Ooohhhhhhhhhhhhhh. I never got that. Thanks:)
    I'll try to rework and follow it correctly. I'm not smart enough to figure these things out on my own.
  2. In Topic: Accurately converting units involving extremely small numers?

    Posted 9 Jul 2014

    View Postbaavgai, on 17 June 2014 - 12:41 PM, said:

    View Postg00se, on 17 June 2014 - 01:32 PM, said:

    you don't want to mix them with double as rounding errors can then creep in.


    Agreed, which is why I didn't. :P
    ...

    Alright, maybe it's a bit late for this, but upon replicating your method (copy-pasting and changing the name) for another set of units, I'm getting an error that I would think shouldn't occur, as it did not in the original enum. They're identical except units and name.

    The method:
    static enum UnitMeas {
    	    Kilogram(1),
    	    Carat(5000),
    	    Centigram(100, 3),
    	    Dekagram(100),
    	    Dram(564383391, -6),
    	    Grain(154323584, -4),
    	    Gram(1000),
    	    LongHundredweight(50802345, -6),
    	    ShortHundredweight(45359237, -6),
    	    Microgram(1000000000),
    	    Milligram(1000000),
    	    Newton(981, -2),
    	    Ounce(35274, -3),
    	    Pennyweight(643014931, -6),
    	    Pound(220462, -5),
    	    Quarter(4409245, -9),
    	    Stone(157473, -6),
    	    TonneUK(984206528, -12),
    	    TonUS(110231, -8),
    	    TonneME(1, -3),
    	    TroyOunce(321507466, -7);
    	    public final BigInteger value;
    	    UnitMeas(long m, int e) { this.value = BigInteger.valueOf(10).pow(e + 10).multiply(BigInteger.valueOf(m)); } //this line
    	    UnitMeas(long m) { this(m, 0); }
    	    public BigDecimal converts(BigDecimal n, UnitMeas to) {
    	        return n.multiply(new BigDecimal(value)).divide(new BigDecimal(to.value), MathContext.DECIMAL128);
    	    }
    	    public BigDecimal converts(double n, UnitMeas to) { return converts(BigDecimal.valueOf(n), to); }
    	    public BigDecimal converts(long n, UnitMeas to) { return converts(BigDecimal.valueOf(n), to); }
    	    public BigDecimal converts(String s, UnitMeas to) { return converts(new BigDecimal(s), to); }
    	}
    


    The error:
    java.lang.ArithmeticException: exp < 0: -2
    at java.math.BigInteger.pow...
    


    When calling this method:
    public String formula(String s, UnitMeas from, UnitMeas to) {
    		return String.valueOf(from.converts(s, to));
    	}
    


    Edit: Why 1852 * 3 on League instead of 5556?
  3. In Topic: Accurately converting units involving extremely small numers?

    Posted 18 Jun 2014

    Quote

    (you guys can debate what you wish, I don't understand most of what you're discussing technically)

    Quote

    That's unfortunate. Not understanding the underlying issues could mean that you're bitten again in the future

    formatting fail
    Yeah, this is mostly a project to get basic understanding of this stuff and how Android works.
    I'm learning, kinda.
  4. In Topic: Accurately converting units involving extremely small numers?

    Posted 17 Jun 2014

    Okay... This all seems fine and dandy (you guys can debate what you wish, I don't understand most of what you're discussing technically).

    It seems to be working accurately now. Thanks so much, all of you!:)
  5. In Topic: Accurately converting units involving extremely small numers?

    Posted 17 Jun 2014

    For the sake of my understanding, I ended up copying and pasting your code with a few minor modifications (to fit in with Android). Everything works great, except leagues. It returns an invalid integer exception on the line I'm performing the conversion on with "ague".
    I'm kinda stumped because with exactly the same line, the other units work.

    Edit: nevermind, I was accidentally calling a separate method on other units. It seems to call Invalid int: "ntimeter" as every character in the name after the first two. Why is this? :whatsthat:

My Information

Member Title:
D.I.C Head
Age:
15 years old
Birthday:
October 22, 1998
Gender:
Location:
Nanaimo, British Columbia, Canada
Interests:
Java, Karate, Hiking, Kayaking, Skiing
Full Name:
Joel Hunter
Years Programming:
2
Programming Languages:
Java, Ruby

Contact Information

E-mail:
Click here to e-mail me
Facebook:
http://www.facebook.com/profile.php?id=100000332985873

Friends

Comments

hunterb100 has no profile comments yet. Why not say hello?