jazzyscript Posted February 13, 2015 Share Posted February 13, 2015 I am trying to make a total that accumulates, like so: $scope.total = 0; ... $scope.total += $scope.amountIn; But even when amountIn is a number, the values are concatenated. Yet if I try a multiplication operation like so: $scope.total = 10 * $scope.amountIn; It does the math! I've never had this problem with regular javascript. Help? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 13, 2015 Share Posted February 13, 2015 Make sure that both arguments are numbers, or else it will concatenate. If it's concatenating then one of those arguments is not a number. Link to comment Share on other sites More sharing options...
jazzyscript Posted February 17, 2015 Author Share Posted February 17, 2015 I fixed it. Had to learn some HTML5. It wasn't a number because I was using input type="text". I thought it would do that conversion automatically. I fixed it with <input type="number" step="0.1"> since I want users to be able to enter floats. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 17, 2015 Share Posted February 17, 2015 You'll still want to convert the value to a number, there are still a lot of browsers in use that don't use the newer HTML 5 field types. They will still be text. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now