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

add decimal at the number

10
hi,

how to add .00 to a number after the onBlur event?

For example,if i key in 123 at the textbox, when i press the tab, it will be appear as 123.00.


thx.
Oct 31 '06 #1
7 6262
hi,

i tried working on your code. i did it the following way.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.     </head>
  4.     <body>
  5.         <input type="text" id="Text1" onFocus="this.focus();" onBlur="this.value = this.value + '.00' " value="">
  6.     </body>
  7. </html>
hope this helps.
Oct 31 '06 #2
java
10
thanks a lot.
Nov 1 '06 #3
java
10
if the situation is:
User key in the number with decimal? how to verify that?

what i mean is if user key in 10.00, it will b remain as 10.00.
If user key in 10, it will appear as 10.00.


thx..
Nov 1 '06 #4
r035198x
13,262 8TB
if the situation is:
User key in the number with decimal? how to verify that?

what i mean is if user key in 10.00, it will b remain as 10.00.
If user key in 10, it will appear as 10.00.


thx..
You could search for the presence of a dot (using a regex) first before you do the change.
Nov 1 '06 #5
AricC
1,892 Expert 1GB
What is the number range that will be entered? You could combine a switch/if with one of these functions.

Number.toFixed(#)
or
Number.toPrecision(#)

HTH,
Aric
Nov 1 '06 #6
java
10
no range. any number can be used.

any suggestion on the way to solve it? Any code?


thx
Nov 2 '06 #7
hi,

use the following code. This might solve your problem:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" onFocus="this.focus();" onBlur="checkDecimal(this,this.value)" value="" />
the javascript function checkDecimal is below:

Expand|Select|Wrap|Line Numbers
  1. function checkDecimal(obj, objStr){
  2.     var objNumber;
  3.     if(isNaN(objStr) && objStr!=''){
  4.         alert('Value entered is not numeric');
  5.         objNumber = '0.00';
  6.     }
  7.     else if(objStr==''){
  8.         objNumber = '0.00';
  9.     }
  10.     else if(objStr.indexOf('.')!=-1){
  11.         if(((objStr.length) - (objStr.indexOf('.')))>3){
  12.             objStr = objStr.substr(0,((objStr.indexOf('.'))+3));
  13.         }
  14.         if(objStr.indexOf('.')==0){
  15.             objStr = '0' + objStr;
  16.         }
  17.         var sLen = objStr.length;
  18.         var TChar = objStr.substr(sLen-3,3);
  19.         if(TChar.indexOf('.')==0){
  20.             objNumber = objStr;
  21.         }
  22.         else if(TChar.indexOf('.')==1){
  23.             objNumber = objStr + '0';
  24.         }
  25.         else if(TChar.indexOf('.')==2){
  26.             objNumber = objStr + '00';
  27.         }
  28.     }
  29.     else{
  30.         objNumber = objStr + '.00';
  31.     }
  32.     obj.value = objNumber;
  33. }
This function will check, if the number entered is numeric, if the decimal numbers take more than two digits, if the first character is a dot, if it has just a dot at the end, or just one decimal number or both the decimal numbers or no decimal number at all.

i hope there are no errors in it.. please check the opening and closing braces, as well as the variable names.
Nov 2 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
10
by: Paul Sullivan | last post by:
decimal d; d = 1.1M OR d= (decimal) 1.1 Discussioon
18
by: Kuljit | last post by:
I am doing Engineering(B.Tech) in Computer Science. I have a question for which i am struggling to write a C code(program). It struck me when we were being taught about a program which counts the...
3
by: ajaksu | last post by:
Hello c.l.p.ers :) Running long(Decimal) is pretty slow, and the conversion is based on strings. I'm trying to figure out whether there is a good reason for using strings like in decimal.py...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
12
by: Frank Millman | last post by:
Hi all I have a standard requirement for a 'decimal' type, to instantiate and manipulate numeric data that is stored in a database. I came up with a solution long before the introduction of the...
10
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole...
0
Frinavale
by: Frinavale | last post by:
Convert a Hex number into a decimal number and a decimal number to Hex number This is a very simple script that converts decimal numbers into hex values and hex values into decimal numbers. The...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.