0

In javascript, we know that some floating point arithmetic will result in values that contain a very small remainder. for example if I open my console and do this math I get this result as seen here

enter image description here

Typically one must know to round after doing these operations. When using parse, and using the increment function. If I have a column called Quantity in my DB and it currently has a value of 6.5 and I call myobject.increment("Quantity", -4.1) we end up with an unrounded value in the DB. the use of increment is required here as many entities may be adjusting this column at or near the same time, so race conditions are a concern.

since the arithmetic happens under the hood, how does parse expect one to handle cases like I mentioned above.

switch201
  • 587
  • 1
  • 4
  • 16
  • How many significant digits do you want? `Math.round` will truncate all the way to an integer. – Jared Smith Dec 06 '21 at 20:53
  • @JaredSmith I don't think I follow can you show me how one would use the parse `increment` function in conjunction with `Math.round` I think the issue is that the math happens inside of the increment function which is a part of parse-platform – switch201 Dec 06 '21 at 21:54

1 Answers1

0

You may do one of two:

  1. Change the logic inside increment function.
  2. Do increment outside and use some setter.

Anyway in case you want to prevent non exact values, you should round it manually. Look here for number rounding answer

Oleg Imanilov
  • 2,591
  • 1
  • 13
  • 26