D
dtshedd
I am having trouble with arguments in a javascript routine. What I am
trying to do is to limit the size of numbers to ten digits but make use
of the significant places if the number is less than one.
I load a box on a form with the following
form.j.value=numToString(somevaluehere)
I have used alert statements to confirm that the value is passed to the
numToString function, but when the number is further passed to the
Precision function it becomes zero. I had read that text strings are
converted to floating point automatically in Javascript, and the number
that is passed to the numToString routine is the result of math
operations.
Appreciate any advice.
TIA
Dan
function numToString(number){
// Convert numeric values to string and truncate
digits=Precision(number)
number=number.toString()
var index= number.indexOf(".",0)
number= number.substring(0,index+(10-digits))
return number
}
function Precision(XV){
// GOSUB FOR SETTING PRECISION OF FORMAT
// LOG function in Basic language is natural log, base 10 conversion
factor 2.3
// Log base 10 of number is the quantity of significant digits, ie log
100=2
if (XV= 0){
XV= 1
}
Idloc = Math.floor(Math.log(Math.abs(XV)) / 2.302585093)
if (Idloc < 3) {
Idloc = 3
}
if (Idloc > 10) {
Idloc = 10
}
return Idloc
}
function numToString(number){
// Convert numeric values to string and truncate
digits=Precision(number)
number=number.toString()
var index= number.indexOf(".",0)
number= number.substring(0,index+(10-digits))
return number
}
trying to do is to limit the size of numbers to ten digits but make use
of the significant places if the number is less than one.
I load a box on a form with the following
form.j.value=numToString(somevaluehere)
I have used alert statements to confirm that the value is passed to the
numToString function, but when the number is further passed to the
Precision function it becomes zero. I had read that text strings are
converted to floating point automatically in Javascript, and the number
that is passed to the numToString routine is the result of math
operations.
Appreciate any advice.
TIA
Dan
function numToString(number){
// Convert numeric values to string and truncate
digits=Precision(number)
number=number.toString()
var index= number.indexOf(".",0)
number= number.substring(0,index+(10-digits))
return number
}
function Precision(XV){
// GOSUB FOR SETTING PRECISION OF FORMAT
// LOG function in Basic language is natural log, base 10 conversion
factor 2.3
// Log base 10 of number is the quantity of significant digits, ie log
100=2
if (XV= 0){
XV= 1
}
Idloc = Math.floor(Math.log(Math.abs(XV)) / 2.302585093)
if (Idloc < 3) {
Idloc = 3
}
if (Idloc > 10) {
Idloc = 10
}
return Idloc
}
function numToString(number){
// Convert numeric values to string and truncate
digits=Precision(number)
number=number.toString()
var index= number.indexOf(".",0)
number= number.substring(0,index+(10-digits))
return number
}