473,411 Members | 2,009 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,411 software developers and data experts.

How could I display 10.00?

function caltotal() {
document.theform.txtTotal=10.00;
}

<form name="theform" ...>
<input type=textbox maxlength=10 size=10 name="txtTotal">
<input type=textbox maxlength=10 size=10 name="input" onchange="caltotal()">
</form>

It just truncates the .00 of txtTotal....
--
iTech Consulting Services Limited
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288
Apr 2 '07 #1
7 1559
On Apr 2, 7:50 pm, Man-wai Chang <toylet.toy...@gmail.comwrote:
function caltotal() {
document.theform.txtTotal=10.00;

}

<form name="theform" ...>
<input type=textbox maxlength=10 size=10 name="txtTotal">
<input type=textbox maxlength=10 size=10 name="input" onchange="caltotal()">
</form>

It just truncates the .00 of txtTotal....
Try the FAQ:

<URL: http://www.jibbering.com/faq/#FAQ4_6 >
--
Rob
Apr 2 '07 #2
<URL: http://www.jibbering.com/faq/#FAQ4_6 >

What's wrong about using toFixed()? It does work at least for the cases
I tested...

--
iTech Consulting Services Limited
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288
Apr 2 '07 #3
On Apr 2, 7:59 pm, "RobG" <r...@iinet.net.auwrote:
[...]
Try the FAQ:

<URL:http://www.jibbering.com/faq/#FAQ4_6>
Sorry, should have mentioned that the code in the above replaces the
native Number.prototype.toFixed method, so if you include it in your
page you can reliably do stuff like:

var price = 12.99;
var tax = 6.5 // 6.5%
var total = price + price*tax/100;
alert( 'Total: ' + total + '\n'
+ 'Rounded: ' + total.toFixed(2) );
--
Rob

Apr 2 '07 #4
On Apr 2, 8:17 pm, Man-wai Chang <toylet.toy...@gmail.comwrote:
<URL:http://www.jibbering.com/faq/#FAQ4_6>

What's wrong about using toFixed()? It does work at least for the cases
I tested...
It is not reliable, try:

var x = 1.035;
var y = 0.0094;
alert( x.toFixed(2) +
'\n' + y.toFixed(2)
);

In IE you will see 1.04 and 0.00, in other browsers (Firefox, Safari,
Opera at least) you will see 1.03 and 0.01. There are many other
examples.

IE's implementation of toFixed is not compliant with the ECMAScript
specification.
--
Rob
Apr 2 '07 #5
In comp.lang.javascript message <11**********************@p15g2000hsd.go
oglegroups.com>, Mon, 2 Apr 2007 03:27:50, RobG <rg***@iinet.net.au>
posted:
>On Apr 2, 7:59 pm, "RobG" <r...@iinet.net.auwrote:
[...]
>Try the FAQ:

<URL:http://www.jibbering.com/faq/#FAQ4_6>

Sorry, should have mentioned that the code in the above replaces the
native Number.prototype.toFixed method, so if you include it in your
page you can reliably do stuff like:

var price = 12.99;
var tax = 6.5 // 6.5%
var total = price + price*tax/100;
alert( 'Total: ' + total + '\n'
+ 'Rounded: ' + total.toFixed(2) );
However, it is often desirable to put a fixed number of characters
before the decimal point, as well as a fixed number of digits after it.
There's no way toFixed can do that, but the code cited, when not used to
emulate toFixed, has that option built in.
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Apr 2 '07 #6
On Apr 3, 6:16 am, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
In comp.lang.javascript message <1175509670.196368.137...@p15g2000hsd.go
oglegroups.com>, Mon, 2 Apr 2007 03:27:50, RobG <r...@iinet.net.au>
posted:
On Apr 2, 7:59 pm, "RobG" <r...@iinet.net.auwrote:
[...]
Try the FAQ:
<URL:http://www.jibbering.com/faq/#FAQ4_6>
Sorry, should have mentioned that the code in the above replaces the
native Number.prototype.toFixed method, so if you include it in your
page you can reliably do stuff like:
var price = 12.99;
var tax = 6.5 // 6.5%
var total = price + price*tax/100;
alert( 'Total: ' + total + '\n'
+ 'Rounded: ' + total.toFixed(2) );

However, it is often desirable to put a fixed number of characters
before the decimal point, as well as a fixed number of digits after it.
There's no way toFixed can do that, but the code cited, when not used to
emulate toFixed, has that option built in.
Many users directed to the FAQ would likely never work out how to use
the code provided, much less discover that the functions can be used
for other purposes. The names of the functions don't help - StrS is
hardly descriptive for a function that formats numbers.

It's a good idea to read the newsgroup c.l.j and its FAQ.
I have no idea whay you include that comment - did I miss something?
See below.
There is nothing in FAQ 4.6 that helps people use the code provided.
Your site provides a vast amount of information but doesn't provide
suitable FAQ-type help. If the FAQ was well worded, there'd be no need
for you to point out that the set of functions in 4.6 can be used for
other purposes.

For example:

function Stretch(Q, L, c) { var S = Q
if (c.length>0) while (S.length<L) { S = c+S }
return S
}

assumes Q and c are strings. To make it a more understandable and a
generic padding function, consider:

function padString( value, newLength, paddingChar)
{
var s = String(value);
var c = String(paddingChar);

if (c.length 0) {
while (s.length < newLength) {
s = c + s;
}
}
return s;
}

alert( padString('abc', 6, '_')); // Shows ___abc
alert( padString(7, 3, '0')); // Shows 007
I'll offer a suggestion next time that entry is the FAQ post of the
day, it probably deserves its own notes page.
--
Rob

Apr 3 '07 #7
In comp.lang.javascript message <11**********************@q75g2000hsh.go
oglegroups.com>, Tue, 3 Apr 2007 06:05:06, RobG <rg***@iinet.net.au>
posted:
>On Apr 3, 6:16 am, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
>It's a good idea to read the newsgroup c.l.j and its FAQ.

I have no idea whay you include that comment - did I miss something?
It's in my "javascript" signature file, which is an editable part (if
selected) of the draft reply. In principle I always leave it in if it
applies particularly to one of those quoted in the article, and also
sometimes when it does not, so that others may see it. But it counts as
body, not sig, being before the sigsep. It also serves as a reminder,
for those who might be mis-lead by others, of how "its" and "it's" are
used in the English language.

> See below.

There is nothing in FAQ 4.6 that helps people use the code provided.
Your site provides a vast amount of information but doesn't provide
suitable FAQ-type help. If the FAQ was well worded, there'd be no need
for you to point out that the set of functions in 4.6 can be used for
other purposes.
That's a matter for the FAQ maintainer. The author of the code in FAQ
4.6 uses somewhat different code now, in which the first parameter is
not assumed or required to be a string and the third is extinct; and the
core routine is also changed. That's been said here before.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
Apr 3 '07 #8

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

Similar topics

3
by: StepH | last post by:
Hi, I'm building a little application, which the goal is to: 1./ Collect data via Serial line and or via a file (for playback). 2./ Display these data as graph, oscilloscope, ... How manage...
1
by: FrankBooth | last post by:
Hello, I have a list of names, and when I click ona name I want the extar info to show and then I want to clcik and hide it again. I have the following HTML which works perfectly if I use one...
23
by: Mat | last post by:
<div id="container"> <div id="main"> <div id="header"> <p class="Address">123 Fake Street, </p> <p class="City">Crazy City, </p> <p class="Province">Ontario </p> <p class="PostalCode">H0H...
3
by: shreddie | last post by:
Could anyone assist with the following problem? I'm using JavaScript to hide/show table rows depending on the option selected in radio buttons. The script works fine in IE but in Firefox the...
1
by: Tristan Miller | last post by:
Greetings. I am trying to write a function which toggles the display of a certain class of <div> elements in an HTML page. The CSS file initially sets some classes to "display: none", and...
7
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is...
0
by: Ferry Boender | last post by:
Hi, I'm relatively new to Xlib programming, and I ran into a little problem. I'm trying to insert keypress events into a X window. The following code works: ...
1
by: RonY | last post by:
I have a dropdown which calls SetTimePeriod method on change the selection. In the JS function, I reset the field style.display based on what the selection is. This works fine with IE but not working...
1
by: rbinington | last post by:
Hi, I am trying to write a DNN module that has the ability to insert articles into an article repository. I want the users to be able to move pages around and enter text into the FCKEditor. I...
15
by: cssExp | last post by:
hello, Rather than going on a wild explanation on what's the the problem, it'll be much quicker and easier if i let you look at it yourself, so I'll post my page source (actual contents taken out,...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.