How can I trim this value stored in cloud Firestore using flutter?

Viewed 43

I'm working on a flutter app. I don't want to convert the value to an Integer and want it to be stored as 75.33. Thanks in advance :)

1 Answers

When sending it to firebase, convert it using .toStringAsFixed(2), if you want it as it is in the image:

double value = 75.333333333333;
print(value.toStringAsFixed(2)); //=> "75.33"

FirebaseFirestore.instance.collection('collectionName').doc('docName').update({'Percentage': value.toStringAsFixed(2)});

(2) is the number of digits you want, if you want it 75.333 use .toStringAsFixed(3).`

Related