HTML5 float to string cast
Monkey Forums/Monkey Bug Reports/HTML5 float to string cast
| ||
| Hi, I think i've discovered a very strange bug that seems to be specific for the html5 target. Just have a look at the source of the test which leads to this result: Running debug js/html5 tests on macos:
bugs.floattostringcasttest.FloatToStringCastTest
TestManualCast
TestCastOnConcatination
TestCastInFuncReturnStatement [FAILED]
There was 1 failure:
1) FloatToStringCastTest.TestCastInFuncReturnStatement in bugs/floattostringcasttest.monkey
Failed asserting that two strings are equal
Expected: 12.0
Actual : 12
FAILURES!
Tests: 3, Failed: 1, Skipped: 0, Incomplete: 0. |
| ||
Looks like a bug all right. Here's a self-contained version:Strict Function Main:Int() Print "" + Float( 12 ) Print Dummy( 12 ) Print Dummy( 12.0 ) Local x:Float = 12 Print Dummy( x ) Return 0 End Function Dummy:String( val:Float ) Return "" + Float( val ) End Output in HTML5: 12.0 12 12 12 Output in GLFW: 12.0 12.0 12.0 12.0 |
| ||
| Casts are currently performed by 'pure' target code, so do differ from one target to another. In general, it's probably not a good idea to expect String(blah) to always equal "blah" for a bunch of reasons. That said, some kind of formatting/sprintf style module that provides at least semi-consistent conversion is probably a good idea. |