N
.nLL
<%=2/33334%>
returns 5.99988000239995E-05
how can i convert it to a n.nn ?
returns 5.99988000239995E-05
how can i convert it to a n.nn ?
<%=2/33334%>
returns 5.99988000239995E-05
how can i convert it to a n.nn ?
..nLL said:<%=2/33334%>
returns 5.99988000239995E-05
how can i convert it to a n.nn ?
VBScript:Recently said:<%=2/33334%>
returns 5.99988000239995E-05
how can i convert it to a n.nn ?
Neil Gould said:VBScript:
<%=Round(2/3334, 2)%>
No, that will actually display simply
0
That's because his number, rounded to 2 decimal places, is 0.00 (no
non-zero digits). But *AS A NUMBER*, there is no difference between
0.00 and just plain 0.
So when you Response.Write zero, you get simply
0
Nothing more.
You *MUST* use
FormatNumber( 2/33334, 2 )
or equivalent if you really want to see
0.00
displayed.
You could bake your own,
giving you power over the rounding process:
========= vbs ==============
function myFormatNumber(n,d)
if n<0 then s = "-" else s = ""
n = fix(abs(n)*10^d + 0.5)
if n=0 then s=""
while len(n)<d+1
n = "0"&n
wend
myFormatNumber = s&left(n,len(n)-d)&"."&right(n,d)
if d=0 then myFormatNumber = s&n
end function
===========================
First of all, that's a fun answer!
============== jscript ===========
function myFormatNumber(n,d){
var s = (n<0)?'-':'';
n = Math.floor(Math.abs(n)*Math.pow(10,d)+.5);
if (!n) s='';
if (!d) return s+n;
n += ''; while (n.length<d+1) n = '0' + n;
l = n.length;
return s+n.slice(0,l-d)+'.'+n.slice(l-d);
};
==================================
But your JS code is using Math.Floor after adding 0.5, which is okay,
but why not just use Math.Round??
Ehhh...but that's a trivial
difference. Nice code. I've seen others do the same thing...in about
4 times as much code.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.