There is a limit on how big your float can be. The documentation says it's -3.4028235E+38. I can confirm that if you try to print out a number bigger than that (like -3.4028236E+38), it turns it into "INF" or "-INF".
So the solution to your problem is to supply a buffer that is 43 characters or larger. Because yeah, if you only supply 42, it could crash.