5

This question already has an answer here:

While looking for an answer of my problem "How to round numbers with decimals in javascript", I found this SO answer https://stackoverflow.com/a/14194399/177665

This can be done using Javascript as follows:

this.value = Math.round((amt*100)/100).toFixed(2));

I try it and notice there is an extra ) at the end producing the following error: SyntaxError: Unexpected token ). So I edit the answer like this:

This can be done using Javascript as follows:

this.value = Math.round((amt*100)/100).toFixed(2);

But I can't save because

Edits must be at least 6 characters; is there something else to improve in this post?

What I am supposed to do? I do not want to modify the answer. Can't we have a checkbox 'code fix' that bypasses this limitation?

marked as duplicate by ale, Danubian Sailor, Martijn Pieters, Lucifer, gnat Jan 10 '14 at 15:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Well, the code doesn't make much sense to me in the first place...shouldn't this be (Math.round(amt*100)/100).toFixed(2);? – Time Traveling Bobby Jan 10 '14 at 10:28
  • You could add an explanation on how the code works, would also make the answer better. – Time Traveling Bobby Jan 10 '14 at 10:28
  • 1
    I could, but I just want to fix it. I am plain beginner with JavaScript. If I knew how to improve the answer, I would not have searched for it and tried to run the code. – cbliard Jan 10 '14 at 10:29
  • 1
    Well, fix it har^H^H^Hmore, while you're at it. The limit is there to prevent meaningless edits, like fixing only one thing and leaving other problems in place. Though, in this case it's complicated, as the code, in my opinion, is not working at all. Given that it is an answer, you could fix that, too, but I'm not sure if that would make sense as the other answer contains the fixed code. Maybe worth a downvote. – Time Traveling Bobby Jan 10 '14 at 10:32
  • 1
    In fact, this is flawed by design: people who read and try answers are the one who will find syntax errors. But as they are looking for an answer they probably do not know a lot about the subject. How can we expect them to improve it? – cbliard Jan 10 '14 at 10:34
  • I could now argue that if people know nothing about the subject, they should not copy code from some website...but let's push that aside. Leaving a comment would be the right course of action in this case. Something like "You have an extra parentheses at the end of your code. Can you also add an explanation on what it does?" – Time Traveling Bobby Jan 10 '14 at 10:38
  • The revision history shows a possibly botched fix, the code is now not what the OP wrote, and the OP is still active on the site. Definitely a comment so OP can fix and clarify. – Bill Woodger Jan 10 '14 at 10:43
  • @TimeTravelingBobby You are right, I copied the code a little too fast here. So I should add a comment? I did it recently on another answer to fix a 404 URL. The new URL was only 5 characters different. The answer was updated 3 days later. In fact when commenting stuff like this, I feel like annoying original poster and adding lot of noise. He probably had more interesting stuff to do than fixing something that I could have fixed myself. – cbliard Jan 10 '14 at 12:56
  • just an awful answer all round IMO, seems to just give a near identical but broken version of the answer posted 5 hours earlier. I'd just down vote and move along. There's a workaround for the 6 char limit posted here – OGHaza Jan 10 '14 at 13:20
  • @OGHaza Thank you for the workaround link. Having such workarounds is strange. If some people use them and they are tolerated, it means it is just a hidden feature reserved to "power-user". Making it a public feature like a "Just fixing stuff" checkbox would be the same. – cbliard Jan 10 '14 at 13:33
  • Tolerated perhaps only because it goes unnoticed, I'm sure any voice of authority would discourage it. If a suggested edit used that trick but left other errors in the post I'd reject it. – OGHaza Jan 10 '14 at 13:39
5

Ideally, take the opportunity to improve the answer in some other way. Correct other errors like spelling and grammar if there are any. Add some explanation of how the code works, or improve the existing explanation. If the question has a failed attempt, explain why that attempt failed or improve the existing explanation.

For example, here, you can change “using Javascript” to “in JavaScript without jQuery”, since that is what distinguishes this answer from the other one.

While you're at it, as noted by Time Traveling Bobby, fix the other misplaced parenthesis: evidently (amt*100)/100 isn't quite right.

Even if you're unsure of what the code means, there's something you can do: test it. This gives you some objective assurance that what you're doing is right. It's not a foolproof method, sometimes your correction will itself have a flaw that your tests don't reveal, but it helps.

If you find no way to edit, but you have at least 50 reputation points, you can leave a comment. Edits are the right way to correct minor mistakes, whereas comments are for transitory issues; but if you can't make an edit, then “there's a mistake” becomes a transitory issue that you're leaving behind for someone else to fix later.

  • @BillWoodger It doesn't really matter, these pages are the same across Stack Exchange. – Gilles Jan 10 '14 at 12:40
  • Thanks for the answer, even if it is off-topic. I tried the code and it works as expected. In fact I did not notice that the code was bogus. I guess in this case I could have improve the answer by more than 6 characters. But not changing "using Javascript” to “in JavaScript without jQuery" because I did not figure it out. – cbliard Jan 10 '14 at 12:46
  • @BillWoodger Ah, yes, I forgot that. Ok, I've changed the links, thanks. – Gilles Jan 10 '14 at 12:55
  • NO problem. Deleting my now-surplus comments. – Bill Woodger Jan 10 '14 at 12:56
  • In fact this 6-characters rule is maybe good: it prevented me from editing a bad answer and keeping it as bad as before. – cbliard Jan 10 '14 at 13:40

Not the answer you're looking for? Browse other questions tagged .