Decimal numbers not adding correctly in AS3 [duplicate] - actionscript-3

This question already has answers here:
Is floating point math broken?
(31 answers)
Closed 7 years ago.
In my program, I have a score multiplier variable of type 'Number'
When I try to add 0.1 to it, I have a problem.
Here is the code:
scoreMultiplier += 0.1;
trace(scoreMultiplier);
scoreMultiplier is originally set to 1, and after the first run through, I correctly get a value of 1.1. However, the second time, the trace shows 1.2000000000000002, and the next time 1.3000000000000003.
There is no other code which modifies scoreMultiplier. This is a problem, first because it is shown on my game screen and goes off the screen, and second because if conditionals where scoreMultiplier==2 for example do not work due to the bizarre fault in the addition.
If anyone knows what's causing this, or at the very least how to truncate the value to 1 decimal place, that would be great.

Flash does not like floating points. At all. Avoid them as much as you can.

Related

How can I access the value inside an HTML span? [duplicate]

This question already has answers here:
Access 'data-' attribute without jQuery
(5 answers)
jQuery: get data attribute
(5 answers)
Closed 5 years ago.
There's this pack simulator on a website I frequent. You are randomly given 10 basketball players in the game with various values on how much they are worth. When you load the page, the cards are face down so you have to click on each one to "reveal" the card and add to your total. The idea is to maximize the value of each pack.
I figured out that the flipping is all show and the total pack score is actually there as soon as you load the page. So I'm trying to write a greasemonkey script to refresh the page until the value is above a certain threshold. I can get to the span with this code:
document.getElementsByClassName("pack-score")[0];
which gets me a span that looks like this:
<span class="pack-score" data-score="12352">
So how would I access the data-score value inside that span, so I can then use it as a value for the code logic?
document.getElementsByClassName("pack-score")[0].getAttribute('data-score')
or in jquery
$(".pack-score").find('span').data('score')

Different display of Dygraphs data in IE and Chrome [duplicate]

This question already has answers here:
javascript Date timezone issue
(3 answers)
Closed 7 years ago.
I'm using Dygraph to show nice graphs of my data. My data has the following structure:
data = [[new Date(\"2015-10-08T11:23:44.712\"),0.01,0.06,0.02],[new Date etc.
This data is supposed to display UTC time, so in the above example it's 11:23. I am living in the Netherlands, where it's UTC +2 in summer time, so the local time is 13:23.
When I check my Dygraph with this data in Chrome, it displays 13:23. However, when I open the same data/graph in Internet Explorer (9, 10 or 11), it displays 11:23 instead of 13:23. It seems to display UTC, not the local.
I have tried to find an answer, but am so far unable to find the reason for the different behavior per browser. To be clear: the data supplied to the graph is always the same, the display is not.
http://dygraphs.com/tests/labelsDateUTC.html was a nice example of UTC display. However, setting labelsUTC to either true or false does not change the display of the time in Chrome, nor IE.
I hope someone can point me in the right direction.
Ok, it might be that I'm just an idiot and that this is why I couldn't find the answer to my problem. Anyway, it seems to be solved. I was playing around with the data string, removing the new Date part (didn't work, broke everything), but then I added the Z and now it does work.
So basically, data should be:
[new Date("2015-10-08T11:23:44.712Z"),0.01,0.06,0.02]
Instead of
[new Date("2015-10-08T11:23:44.712"),0.01,0.06,0.02]
Notice the absence of the Z in the wrongful version. I find it interesting that Chrome doesn't need the Z and IE does, but well.

How to check visibility of object using qtp [duplicate]

This question already has an answer here:
How do I handle object existence with QTP?
(1 answer)
Closed 9 years ago.
i have a requirement to verify that for a selected value in a drop down list in a webpage, one text box in the same page gets invisible or not. But when i checked the run time properties (disabled and invisible) of the textbox, in both cases i.e. when visible in the page and when not visible in the page.. both the properties are coming out to be same in both cases. What else i can do to verify the same. I am using qtp 11.0
You could try using readonly property of text field.
Thanks.

Possible to make CSS3 dynamic for a number of classes?

First off, im sorry if the following question is way to vague and unprecise, but this was my best explanation:
I've just started going trough HTML5 & CSS3. I'm drawing a line from point x1y1 to x2y2 with css3.
My question is, is there some way to dynamically call css3 code?
For example, say i have 10 names in a database, i want to place them inside the HTML doc and draw a line to each name from the center. Like a sun (the center) and the sunbeams (with the names at the end).
So for lets say name1 from the center of the "sun" points out 10degrees, the next beam could be 15 and the next after that 20 and so on..
2 days later the database might contain 20 names for which i want 20 sunbeams pointing out but without having to add 10 more .classnames stuff in my CSS3 doc
Is this even possible?
Thanks! :)
EDIT: Typo
You can have another common class name for all beams say "beam_class" and define their properties in it, so you don't have to worry about the creating new classes for each beam.

show and hide DIVS at a given time

I'm in big trouble, I'm creating a multiple choice questionnaire, where each issue is a DIV, I need a javascript that apart from the DIVS roll at a given time, the screen shows the seconds this time, the problem is that every question must have a time
different, eg the No. 1 already has 10 seconds to question No. 2 is 15 seconds, for example, can anyone help me?
I suggest you to use setTimeout Jquery's function, playing with getElementById('yourid').style.display = "none";
Here's an Example I made for you.