473,395 Members | 1,554 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,395 software developers and data experts.

Formatting decimal values for values from Request.Form

15
Hello all,

I ask this question because I searched and did not find anything that related to this query. My apologies if this is a mistake.

Please see the following code. I am using 2 ASP pages. One to fill up a decimal value (it is actually the unit price of something) and the other to receive and process it. The value in the first page can be entered by the user as a whole number OR as a number with decimal places. Ex. 2345.88 since products tend to have that kind of values.


Now this is in the second ASP page where I receive it.
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. Dim price
  4.  
  5. ' Let us assume I entered 1245.76 in the previous form
  6. price = Request.form("price")
  7. Response.write price
  8.  
  9. 'The above print will show 1245.76 without problems. So far so good.
  10.  
  11. 'But then I do some math with it and print it.
  12.  
  13. price = price * 5.5
  14. Response.write price %>
  15.  
And this time it prints 685168 where as it should print 6851.68 and hence the data is completely incorrect.

I tried FormatNumber which did not work. Someone suggested "&FormatNumber(price,2)&" which also did not work.

Help please!

Thank you so much.

Sk
Sep 8 '07 #1
11 3121
jhardman
3,406 Expert 2GB
Sk,

That's odd. I just tried it here and it worked fine.

Jared
Sep 10 '07 #2
irkahs
15
Sk,

That's odd. I just tried it here and it worked fine.

Jared

yes....it does work fine in your example. In mine it still does not work properly. Any functions or formatting structures you might know to help me with this?

Please help.

Sk
Sep 13 '07 #3
jhardman
3,406 Expert 2GB
yes....it does work fine in your example. In mine it still does not work properly. Any functions or formatting structures you might know to help me with this?

Please help.

Sk
I can't think of anything off hand, maybe if I saw your code...

Are you using a formatPercent or something similar at some point?

Jared
Sep 13 '07 #4
irkahs
15
I can't think of anything off hand, maybe if I saw your code...

Are you using a formatPercent or something similar at some point?

Jared

Nope. Nothing of that sort. Just a plain old Request.QueryString from a textbox of another ASP file. The value that enters the second page is stored as Dim and thats about it.

Could this be some server sided issue? Like some regional setting on the server that its running on? What do you think?


Sk
Sep 14 '07 #5
markrawlingson
346 Expert 100+
The example that you originally provided is completely sound, there's no reason for that simple example not to work, which makes me think there's got to be something in your code interfering with it and dropping the decimal places somewhere.

To be of any help to you I think we'll need to see your code.

You're not treating the number with any numerical functions are you? A lot of numerical functions like CInt() in asp will kill the decimal places and turn it into a whole number, or just drop the decimal numbers all together in order to derive a whole number.

My best guess is that you've probably got something like that in there, but If that's not the case - show your code so we can look through it and see what's going on.
Sep 15 '07 #6
irkahs
15
Here is the code sample. Kindly help.


test.asp
-----------

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
  5. <meta name="ProgId" content="FrontPage.Editor.Document">
  6. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  7. <title>New Page 1</title>
  8. </head>
  9.  
  10. <body>
  11.  
  12. <form method="GET" action="displayDec.asp">
  13.   <p><input type="text" name="price" size="20"></p>
  14.   <p><input type="submit" value="Submit" name="B1"></p>
  15. </form>
  16.  
  17. </body>
  18.  
  19. </html>
  20.  

displayDec.asp
---------------------
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. Dim price
  4.  
  5. price = Request.QueryString("price")
  6. Response.Write("Before multiplying it: " & price)
  7. price = price * 7.2
  8. Response.Write("<br>" & "After multiplying it with 7.2 : " & price)
  9. %>
SAMPLE OUTPUTS (and a NEW error! :( )
--------------------------

If I enter 2.0 in price then it prints 144.
If I enter just the number 2 in price then it prints 14,4 (this did not happen before. I don't know why it is printing a COMMA now instead of a decimal place!!!!)
If I enter 0.01 then it prints 7,2 (again the comma appears)


PLEASE help guys. This thing is totally freaking me out. :(

Cheers,

Sk
Sep 15 '07 #7
jhardman
3,406 Expert 2GB
Here is the code sample. Kindly help.


test.asp
-----------

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
  5. <meta name="ProgId" content="FrontPage.Editor.Document">
  6. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  7. <title>New Page 1</title>
  8. </head>
  9.  
  10. <body>
  11.  
  12. <form method="GET" action="displayDec.asp">
  13.   <p><input type="text" name="price" size="20"></p>
  14.   <p><input type="submit" value="Submit" name="B1"></p>
  15. </form>
  16.  
  17. </body>
  18.  
  19. </html>
  20.  

displayDec.asp
---------------------
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. Dim price
  4.  
  5. price = Request.QueryString("price")
  6. Response.Write("Before multiplying it: " & price)
  7. price = price * 7.2
  8. Response.Write("<br>" & "After multiplying it with 7.2 : " & price)
  9. %>
SAMPLE OUTPUTS (and a NEW error! :( )
--------------------------

If I enter 2.0 in price then it prints 144.
If I enter just the number 2 in price then it prints 14,4 (this did not happen before. I don't know why it is printing a COMMA now instead of a decimal place!!!!)
If I enter 0.01 then it prints 7,2 (again the comma appears)


PLEASE help guys. This thing is totally freaking me out. :(

Cheers,

Sk
Is there some reason you can't use method=post rather than method=get? I'm not sure if this is causing a problem, but it might. Things sent by querystring need to be formatted for putting in the querystring and I think a period is a special character in a URL.

Using a comma rather than a decimal point is a region-specific behavior. Check your server's region settings.

Jared
Sep 15 '07 #8
irkahs
15
Is there some reason you can't use method=post rather than method=get? I'm not sure if this is causing a problem, but it might. Things sent by querystring need to be formatted for putting in the querystring and I think a period is a special character in a URL.

Using a comma rather than a decimal point is a region-specific behavior. Check your server's region settings.

Jared
Dear Jared,

That is what I thought as well. But I tried it with POST and Request.Form and the same thing happens. So I don't think it is the GET which is causing the problem.

So could you please help in showing how exactly values are formatted for such scenarios using QueryString?

And you are right. I am pretty sure it has something to do with the server settings here. I will have to look into that.

Thank you.

Sk
Sep 16 '07 #9
markrawlingson
346 Expert 100+
I agree with Jared, it's got to be something server specific. In fact, almost all regions use a comma instead of a period to donate a decimal place, So i would definately check that first. Though, after running your code I did change the region on my personal computer and my server to finish and re-ran the page and did not get a comma as a decimal place.

I ran your exact code, without modifying it, and the following was returned:

Before multiplying it: 7
After multiplying it with 7.2 : 50.4

Correct calculation and correct use of decimal places etc.
Sep 16 '07 #10
irkahs
15
I agree with Jared, it's got to be something server specific. In fact, almost all regions use a comma instead of a period to donate a decimal place, So i would definately check that first. Though, after running your code I did change the region on my personal computer and my server to finish and re-ran the page and did not get a comma as a decimal place.

I ran your exact code, without modifying it, and the following was returned:

Before multiplying it: 7
After multiplying it with 7.2 : 50.4

Correct calculation and correct use of decimal places etc.

Hmm....I dont know what else to do now. I even showed the problem to my network admin here but she insists it is not a server related issue. I have given her the code....lets see what happens.

Thank you.

Sk
Sep 17 '07 #11
markrawlingson
346 Expert 100+
It has to be, I honesly don't see what else it could be! If Jared and I can copy and paste your exact code that you specified in previous post(s) and run it on our servers and it does return the desired result, but doesn't on the server which you're running it on - then there's only one difference there. That difference being the environment that it's being run in.

Well, hopefully he/she can come up with something to fix the problem!
Sep 17 '07 #12

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

Similar topics

1
by: Techy | last post by:
I have hancoded the asp page for inserting the values into an Ms Access > Database and it work fine > > The problem I am facing is that once I insert any value with Decimals like " > 11.95" or...
7
by: Chad Z. Hower aka Kudzu | last post by:
I have a typed dataset that is on a WinForm and I have labels that have their text properties bound to fields in a data table. The values are of type decimal. When I dispaly them in the label, I...
4
by: Tommi Mäkitalo | last post by:
Hi I need to format floating-point-numbers with exact 2 digits after decimal point. I could use printf with "%.2f", but it don't use std::locale. Any ideas? -- Tommi Mäkitalo
16
by: Douglas | last post by:
Gday, How would I format a number so that: TheValue = 32500 Displays in the TextBox as: $32,500.00
4
by: Dave Brydon | last post by:
Access 2003 I have a combo box in my personnel table, which draws its data from a trade code table; the original field in the code table, is numeric, Long Integer, and formatted with 5 zero's . ...
7
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34...
2
by: Earl | last post by:
Still trying to clean up some datagrid formatting issues from the past. When I bring in money values from a stored procedure, I'm getting 4 decimal places in the grid ( which of course I only...
14
by: Scott M. | last post by:
Ok, this is driving me nuts... I am using VS.NET 2003 and trying to take an item out of a row in a loosely-typed dataset and place it in a label as a currency. As it is now, I am getting my...
2
Pittaman
by: Pittaman | last post by:
Hello I am creating some crystal reports (for visual studio 2005) based on the content of certain .NET objects. I'm doing this in .NET 2.0. For one of them I'm using a Cross-table to summarize...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.