473,408 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

divisiorn problem

<%=2/33334%>

returns 5.99988000239995E-05

how can i convert it to a n.nn ?
Jun 27 '08 #1
8 1636
..nLL wrote on 16 mei 2008 in microsoft.public.inetserver.asp.general:
<%=2/33334%>

returns 5.99988000239995E-05

how can i convert it to a n.nn ?
Use:

<% = "n.nn" %>

;-)
Better lookup vbs: FormatNumber()
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #2
Recently, .nLL <no***@here.composted:
<%=2/33334%>

returns 5.99988000239995E-05

how can i convert it to a n.nn ?
vbscript:

<%=Round(2/3334, 2)%>

Best,

Neil

Jun 27 '08 #3
..nLL wrote:
<%=2/33334%>

returns 5.99988000239995E-05

how can i convert it to a n.nn ?
That is a string formatting question. And since ASP is not a language, it
must be answered with respect to the language you are using. Check out
VBScript's FormatNumber:
http://msdn.microsoft.com/en-us/libr...sk(VS.85).aspx

or JScript's Number.toFixed():
http://msdn.microsoft.com/en-us/libr...0z(VS.85).aspx

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jun 27 '08 #4

"Neil Gould" wrote:
Recently, .nLL <no***@here.composted:
<%=2/33334%>

returns 5.99988000239995E-05

how can i convert it to a n.nn ?
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.
Jun 27 '08 #5
=?Utf-8?B?T2xkIFBlZGFudA==?= wrote on 26 mei 2008 in
microsoft.public.inetserver.asp.general:
>
"Neil Gould" wrote:
>Recently, .nLL <no***@here.composted:
<%=2/33334%>

returns 5.99988000239995E-05

how can i convert it to a n.nn ?
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
===========================



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #6
Evertjan. wrote on 26 mei 2008 in microsoft.public.inetserver.asp.general:
>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
===========================
============== 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);
};
==================================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #7
First of all, that's a fun answer!

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.


Jun 27 '08 #8
=?Utf-8?B?T2xkIFBlZGFudA==?= wrote on 26 mei 2008 in
microsoft.public.inetserver.asp.general:
First of all, that's a fun answer!
[please always quote on usenet]

Added:
============== 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??
Because as I said,
I want complete control over the rounding process.
And I want to be able to use a decimal point or decimal comma,
And I want to be able to set the minus behind the numberstring
or have a &nbsp; filler character where and if there is no minus sign,
or use a + character.

All this is possible if you do your own number to string formatting.
Ehhh...but that's a trivial
difference. Nice code. I've seen others do the same thing...in about
4 times as much code.
As I stem from prehistoric assembler coding time,
writing compact code still feels as the ultimate bliss.

What is missing is error testing for noninteger or negative values of the
number of decimals parameter.

By adding as the first line in the js function:

if (d===undefined) d = 2;

It that parameter defaults to a 2 decimal format.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.