Search code examples
javaandroidfirebasegoogle-cloud-firestoredata-retrieval

How to retrieve float from Firestore?


Hi I have problem with retrieving data from Firestore. I don't know how to retrieve data from number field with dot.

For example Prize : 2.54

I tried this

longPrize = documentSnapshot.getLong("Prize");

but it don't work because it's returns only 2. I have to get 2.54 as result. How I can do this ? Unfortunately Firebase don't support retrieving data in float form (getFloat() doesn't exist).


Solution

  • If you have a floating point number in a document field, you can use getDouble() to access it as a Double. If you want to cast that to a float, that's up to you.

    Also read: Float and double datatype in Java