Javascript parseFloat() change number [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a strange problem with JavaScript .
I have text value in a textbox '25000000' when i am
using parsefloat(txt.value), the returned value is 25000 !??
Why is 25000000 changed to 25000 ?

I think there is an alphabet somewhere in your numbers. Check the example below.There is an error in your code.
parseFloat(" 250000000 ") = 250000000
parseFloat("2018#geeksforgeeks") = 2018
parseFloat("geeksforgeeks#2018") = NaN

Thanks for all Responses.
The problem was for ',' in price.
Of course we replace ',' with '' ,but replace method
only change first one like "25,000,000,000"=>"25000,000,000".
I used str.split(',').join('') and problem solve and parsefloat returned correctly.
regards
ali

Related

Javascript Couldn't Pickup InnerHTML [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 months ago.
Improve this question
Here is my page element:
Then I tried to pick up the value demo#.... from the element class name user-name using these code:
var x = document.getElementsByClassName("user-name")[0].innerHTML;
console.log("x is: " + x);
It would return me:
x is:
Any idea how to fix this?
Looking at your approach, the code innerHTML should have worked, there might be some other issue which might be occurring.
Like 1) there might be other tag with same class name, 2) the username value might not be updated when you called the function.

Special Character codes to Normal symbol - JavaScript [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a dropdown showing list of languages,
Now, some of these languages contains special HTML characters, but I want to show the real values of those characters.
Like.
&egrave should be replaced with รจ
How to do this using Javascript ?
Thanks in advance !!
One way to do this:
const decodeHtml = (html) => {
const t = document.createElement("textarea");
t.innerHTML = html;
return t.value;
}

arithmetic operation using JavaScript [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
i am trying to perform addition in javascript. below is my code :
function myfunc(size){
var m = parseInt(size)+5;
alert(m );
When i use 'alert',it works perfectly.. but i want to use sweet alert and it is not display anything via sweet alert. when i do:
function myfunc(size){
sweetAlert(size );
it does display the size using the code above. the problem is, it doesn't work when i try to perform the addition. why is it so?
try something like this
import swal from "sweetalert";
function myfunc(size) {
var m = parseInt(size) + 5;
swal(String(m));
}
myfunc("6");

For loop skipping index in JavaScript [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I wrote a for loop in JavaScript which is simple and straight forward. But, it is skipping the 2nd index. I don't understand why?
Below is my code snippet :
if($scope.usersChoice.length == $scope.correctAnswers.length){
for(var p=0;p<$scope.usersChoice.length;p++) {
if($scope.usersChoice[p] == $scope.correctAnswers[p]){
$scope.score++;
}
}
}
Here the length is 10.
How do you know it is skipping the 2nd index? Because it should'nt.
Can you show us your arrays ?
By the way, you can use forEach instead of for loop in this case, since you don't seem to need to break your loop:
if($scope.usersChoice.length == $scope.correctAnswers.length){
$scope.usersChoics.forEach($choice,$index=>{
if($choice === $scope.correctAnswers[$index]) $scope.score++;
});
}

How to add var in get value in JavaScript? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
How to add var in get value in JavaScript ?
I have 2 var
var page = $('#demoajax').val();
var name = $("#users").val();
This is mym old code
data:"server=Windows&actionfunction=showData&page="+page,
I want to add var name and value now=date to this line how can I do that ?
First I try this
data:"username="+name+"&server=Windows&actionfunction=showData&page="+page+"&now=date",
But not work.
You appear to have inserted your changes in the middle of the query string. Try this instead.
data:"server=Windows&username="+name+"&actionfunction=showData&page="+page+"&now=date",
Why do you have data:"username="+name+"&server=Windows&actionfunction=showData&page="+page+"&date=now",
switch date and now
Also lose the comma at end if not needed

Categories