title: Get Double From Firebase
body: <p>I am trying to get a double from firebase object using dataSnapshot but each time I try to, I'm getting an error saying that <code>java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double</code> and when I try to maybe Cast it to a Long just to observe what's gonna happen I get this Error <code>java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Long</code>, so in short the error is vice versa. This is the code I'm using to get my total in Firebase dataSnapshot:</p>
  
  <pre><code> mDatabaseReference.child(mAuth.getCurrentUser().getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
  
              if (!isPrinted) {
                  System.out.println("Children" + dataSnapshot.getChildrenCount());
                  for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                      Double price = (Double) snapshot.child("total").getValue();
                      System.out.println("Price: " + String.valueOf(price));
                  }
                  isPrinted = true;
              }
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
          }
      });
  </code></pre>
  
  <p>and this is the code I'm using to save the total on firebase:</p>
  
  <pre><code>double total = holder.quantity * price;
                     dataSnapshot.child(code).child("total").getRef().setValue(total);
  </code></pre>
  
  <p>I'm looking to retrieve the total from firebase using <code>Double</code> but it gives me the <code>ClassCastException</code>. Please help with a solution.
  I also tried looking <a href="https://stackoverflow.com/questions/41691463/how-to-retrieve-double-values-saved-under-one-key-in-firebase#">here</a> for a solution but did not find anything </p>
  
  <p>This is my FirebaseDatabase where I'm querying from: <a href="https://i.stack.imgur.com/B6vr4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B6vr4.png" alt="enter image description here"></a></p>