Javascript integer as double

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

fzuleta
Posts: 13
Joined: 08 Oct 2013, 02:15

Javascript integer as double

Postby fzuleta » 02 Apr 2015, 17:58

Hi!

when sending an extension request, Im trying:

var bet = 1;
var o ={};
o.bet = bet.toFixed(2); // also tried bet + 0.00

and sending it off in an extension request.

on the server I have params.getDouble("bet");

but it gives me a Integer to Double cast exception. any ideas on whats the proper way of sending it?

the only way I currently get it to work is if I do: bet + 0.0001 which is not right
Im using SFS2X 2.9.2
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Javascript integer as double

Postby Lapo » 03 Apr 2015, 09:58

Hi,
since Javascript doesn't support static types, they must be detected at runtime.
If a value doesn't have decimals it is considered and Int.

In this case I would probably recommend using Strings to avoid type cast problems on the server side.

What you did with the .toFixed(2) call is actually transforming the number to a String.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 17 guests