0

Basically, I'm using app42 to store scores for a game. However my game uses times.

For example. If I submit a score of 0:3:85 ( 0 hours, 3 seconds and 85 milliseconds)

it would be stored as a bigdecimal as 385.

When i retrieve my score I retrieve it as 385, I have no idea how I can convert it back to my time format. Example: enter image description here

At the minute i'm using a function to count how many digits the number is.

    int getNumberOfDecimalPlaces(BigDecimal bigDecimal) {
    String string = bigDecimal.toPlainString();
    int index = string.length();
    return index;
}

then to actually work it out, i'm at a loss. Im thinking something along the lines of

    private String ConvertScore(BigDecimal Score){
    int Len = getNumberOfDecimalPlaces(Score);
    String Convert = Score.toString();
    String Finished;
    if( Len == 1){
    }
    else if(Len == 2){

    }
    else if(Len == 3)
    {
        Finished
    }
    return Finished;
}

but honestly I can't even think how i'd do it.

Thanks

Rhys Drury
  • 305
  • 2
  • 20

1 Answers1

0

Correct me if I'm wrong but your API that you're using returns you the score of the game (not the, not the time. And you won't have an ability to convert it correctly. Because there could be different score.

For example, how to convert 10345?

10 hours 3 seconds and 45 milliseconds

OR

is it 103 hours 0 seconds and 45 milliseconds and so on.

Yuri
  • 1,748
  • 2
  • 23
  • 26
  • Yeah it returns the score which is converted from a time. What I was thinking is that it could be converted by how short it is, so if it's 2 digits, its milliseconds, if its 3 or 4 its seconds if its longer its minutes etc – Rhys Drury Nov 14 '15 at 18:55
  • @RhysDrury Hmm, but how to predict (from example 10345) whether it is 345 milliseconds or 45 or 5 milliseconds? :) – Yuri Nov 14 '15 at 18:57
  • Well how it's calculated is like this int secs = (int) (updatedTime / 1000); int mins = secs / 60; secs = secs % 60; int milliseconds = (int) (updatedTime % 100); which is from UpdatedTime which is from my timer. Is there a way to keep the formatting the same in a big decimal, such as keeping the 0's in, so in your example it'd be 10.03.45 for 10 minutes 3 seconds and 45 milliseconds? – Rhys Drury Nov 14 '15 at 19:02
  • Please update your question. It contains inaccuracies as for your basic example `If I submit a score of 0:3:85 ( 0 hours, 3 seconds and 85 milliseconds) it would be stored as a bigdecimal as 385.` – Yuri Nov 14 '15 at 19:08
  • Not sure what you mean but i have now included an image as to how the times are saved – Rhys Drury Nov 14 '15 at 19:14
  • I'll have a try of that and let you know – Rhys Drury Nov 14 '15 at 19:19