setAttribute with a floating point value

 

We received this bug report: "0,5" is an invalid priority value. We could not reproduce this problem and at first we were at a lost what the cause could be.

It turned out that we have some code that calculates XSLT priorities, which ends with:

template.setAttribute("priority", priority);

This looks innocent enough, but priority is a floating point value here. Apparently MSXML accepts any kind of value to setAttribute, and uses its own routines to convert the value to string. But these conversion routines use the regional settings of the computer. So when you pass the value 0.5 to setAttribute on a machine that has f.e. Dutch regional settings, the value becomes "0,5", which is invalid XSLT. Now knowing this, the solution was simple:

template.setAttribute("priority", "" + priority);

Comments

anonymous user
Jul 08 2008
This looks innocent enough, but priority is a floating point value here http://nevaauto.ru/

HTML will be shown as HTML code.
Linebreaks and Links starting with http:// are automatically resolved