I've written a little function to remove everything after the 2nd decimal
place for prices which is as follows: -
ReturnConverted Currency = (fix(iSterling * session("Exchan geRate") *
100) / 100)
However, it sometimes returns incorrect values. i.e. Why does the
following: -
response.write( FormatNumber((f ix(2.30 * 1 * 100) / 100) , 2))
or
response.write( FormatNumber((i nt(2.30 * 1 * 100) / 100) , 2))
return 2.29 ?
Any help would be greatly appreciated as I've been ripping my hair out for a
few hours trying to solve this one.
Ted. 7 2512
I didn't know this existed in Fix as well. http://www.aspfaq.com/2477
Don't know why you need fix or int here though. These work fine for me:
response.write( FormatNumber((2 .30 * 100)/100.0, 2))
response.write( FormatPercent(( 2.30)/100.0, 2))
-- http://www.aspfaq.com/
(Reverse address to reply.)
"Ted" <sp**@spam.co m> wrote in message
news:Og******** ******@TK2MSFTN GP12.phx.gbl... I've written a little function to remove everything after the 2nd decimal place for prices which is as follows: -
ReturnConverted Currency = (fix(iSterling * session("Exchan geRate")
* 100) / 100)
However, it sometimes returns incorrect values. i.e. Why does the following: -
response.write( FormatNumber((f ix(2.30 * 1 * 100) / 100) , 2))
or
response.write( FormatNumber((i nt(2.30 * 1 * 100) / 100) , 2))
return 2.29 ?
Any help would be greatly appreciated as I've been ripping my hair out for
a few hours trying to solve this one.
Ted.
> Don't know why you need fix or int here though. These work fine for me: response.write( FormatNumber((2 .30 * 100)/100.0, 2)) response.write( FormatPercent(( 2.30)/100.0, 2))
The reason I am using fix() is so: -
response.write( FormatNumber((f ix(2.309 * 1 * 100) / 100) , 2))
will result in 2.30
Maybe I'm goint to have to re-think my appraoch to this problem.
As it's an eCommerce site I'm putting together, I need the maths to add up
precisely on the basket screen etc. I have got some functions that will
inevitably return pesky floats (adding 17.5% tax, currency conversions etc).
What I was doing was chopping off everthing after the second decimal place
in all of my calculations using the function I mentioned. This, until now,
had worked OK and all the totals had added up. Until I got the dreaded 2.30
resulting in 2.29.
Any ideas how I should tackle this problem?
Thanks for the reply,
Ted. I've written a little function to remove everything after the 2nd
decimal place for prices which is as follows: -
ReturnConverted Currency = (fix(iSterling *
session("Exchan geRate") * 100) / 100)
However, it sometimes returns incorrect values. i.e. Why does the following: -
response.write( FormatNumber((f ix(2.30 * 1 * 100) / 100) , 2))
or
response.write( FormatNumber((i nt(2.30 * 1 * 100) / 100) , 2))
return 2.29 ?
Any help would be greatly appreciated as I've been ripping my hair out
for a few hours trying to solve this one.
Ted.
Is it really correct to just truncate digits instead of rounding? I would
think that, especially for an e-commerce site, you would be more interested
in being correct than using fix().
-- http://www.aspfaq.com/
(Reverse address to reply.)
"Ted" <sp**@spam.co m> wrote in message
news:uU******** ******@TK2MSFTN GP12.phx.gbl... Don't know why you need fix or int here though. These work fine for me:
response.write( FormatNumber((2 .30 * 100)/100.0, 2)) response.write( FormatPercent(( 2.30)/100.0, 2)) The reason I am using fix() is so: -
response.write( FormatNumber((f ix(2.309 * 1 * 100) / 100) , 2))
will result in 2.30
Maybe I'm goint to have to re-think my appraoch to this problem.
As it's an eCommerce site I'm putting together, I need the maths to add up precisely on the basket screen etc. I have got some functions that will inevitably return pesky floats (adding 17.5% tax, currency conversions
etc). What I was doing was chopping off everthing after the second decimal place in all of my calculations using the function I mentioned. This, until now, had worked OK and all the totals had added up. Until I got the dreaded
2.30 resulting in 2.29.
Any ideas how I should tackle this problem?
Thanks for the reply,
Ted.
I've written a little function to remove everything after the 2nd decimal place for prices which is as follows: -
ReturnConverted Currency = (fix(iSterling *
session("Exchan geRate") * 100) / 100)
However, it sometimes returns incorrect values. i.e. Why does the following: -
response.write( FormatNumber((f ix(2.30 * 1 * 100) / 100) , 2))
or
response.write( FormatNumber((i nt(2.30 * 1 * 100) / 100) , 2))
return 2.29 ?
Any help would be greatly appreciated as I've been ripping my hair out for a few hours trying to solve this one.
Ted.
If I use currency formats then there may be descrepancies when totaling the
basket (amongst other things)
i.e. after adding VAT or coverting a currency item values might end up
like: -
£3.0090
£5.1070
which appear to the user as: -
£3.01
£5.11
but totals as: -
£8.13
Problems also occur when bankers rounding is introduced. I just want
everything to be predictable. Any suggestions for the best way to achieve
this?
Regards,
Ted. Is it really correct to just truncate digits instead of rounding? I would think that, especially for an e-commerce site, you would be more
interested in being correct than using fix().
-- http://www.aspfaq.com/ (Reverse address to reply.)
"Ted" <sp**@spam.co m> wrote in message news:uU******** ******@TK2MSFTN GP12.phx.gbl... Don't know why you need fix or int here though. These work fine for
me: response.write( FormatNumber((2 .30 * 100)/100.0, 2)) response.write( FormatPercent(( 2.30)/100.0, 2))
The reason I am using fix() is so: -
response.write( FormatNumber((f ix(2.309 * 1 * 100) / 100) , 2))
will result in 2.30
Maybe I'm goint to have to re-think my appraoch to this problem.
As it's an eCommerce site I'm putting together, I need the maths to add
up precisely on the basket screen etc. I have got some functions that will inevitably return pesky floats (adding 17.5% tax, currency conversions
etc). What I was doing was chopping off everthing after the second decimal
place in all of my calculations using the function I mentioned. This, until
now, had worked OK and all the totals had added up. Until I got the dreaded
2.30 resulting in 2.29.
Any ideas how I should tackle this problem?
Thanks for the reply,
Ted.
> I've written a little function to remove everything after the 2nd decimal > place for prices which is as follows: - > > ReturnConverted Currency = (fix(iSterling * session("Exchan geRate") * > 100) / 100) > > However, it sometimes returns incorrect values. i.e. Why does the > following: - > > response.write( FormatNumber((f ix(2.30 * 1 * 100) / 100) ,
2)) > > or > > response.write( FormatNumber((i nt(2.30 * 1 * 100) / 100) ,
2)) > > return 2.29 ? > > Any help would be greatly appreciated as I've been ripping my hair
out for a > few hours trying to solve this one. > > Ted. > >
> i.e. after adding VAT or coverting a currency item values might end up like: -
£3.0090 £5.1070
which appear to the user as: -
£3.01 £5.11
but totals as: -
£8.13
Problems also occur when bankers rounding is introduced. I just want everything to be predictable. Any suggestions for the best way to achieve this?
Yes. Round each product to the nearest penny, instead of adding products
together at fractions of pennies (introducing the possibility of rounding
down by mistake). In the above example, you should be adding 3.01 and 5.11
and getting 8.12. Why would you carry forward 3.0090? If they only bought
one product, would you charge them 3.0090? Of course not.
A better "fix" function isn't going to fix your problem, if you'll pardon
the pun.
Hi Ted,
I don't understand why you said total is 0.13.
0.0090+0.1070=0 .1160
0.01+0.11=0.12
It cannot be 0.13.
Luke
I definitely understand that certain operations used on an ecommerce site
will give pesky floats, as you mentioned:
As it's an eCommerce site I'm putting together, I need the maths to add up
precisely on the basket screen etc. I have got some functions that will
inevitably return pesky floats (adding 17.5% tax, currency conversions etc).
But rather than change your formatting and rounding techniques, I would
suggest adding the total in whatever currency the prices were originally
given in, and then multiplying that total by the exchange rate and tax
percentages. That way, you will not need to worry about adding fractions of
a cent (or whatever currency is being used); you can simply round or
concatenate the decimal places one time for the total rather doing it for
every item. Example (my conversion & tax factors may be wrong here):
Cost Conv Tax
£15.99 * 1.76 * 17.5% = 33.06732 = 33.06
£10.50 * 1.76 * 17.5% = 21.714 = 21.71
£ 8.27 * 1.76 * 17.5% = 17.10236 = 17.10
71.88368 = 71.88 (This is of by
..01)
OR
Cost Conv Tax
£15.99
£10.50
£ 8.27
£34.76 * 1.76 * 17.5% = 71.88368 = 71.88 (This does not show any unexpected
decimals)
If only some items are taxed, you may need to add up the taxable and
non-taxable items separately, but otherwise the same. You may want to
display the operations differently on the site, and I am not experienced in
economics or finance, but I usually see tax and conversions done at the end,
which I believe makes it simpler for both the user and in the code. Just a
suggestion.
--
Nathan Sokalski nj********@hotm ail.com www.nathansokalski.com
"Ted" <sp**@spam.co m> wrote in message
news:uU******** ******@TK2MSFTN GP12.phx.gbl... Don't know why you need fix or int here though. These work fine for me:
response.write( FormatNumber((2 .30 * 100)/100.0, 2)) response.write( FormatPercent(( 2.30)/100.0, 2)) The reason I am using fix() is so: -
response.write( FormatNumber((f ix(2.309 * 1 * 100) / 100) , 2))
will result in 2.30
Maybe I'm goint to have to re-think my appraoch to this problem.
As it's an eCommerce site I'm putting together, I need the maths to add up precisely on the basket screen etc. I have got some functions that will inevitably return pesky floats (adding 17.5% tax, currency conversions
etc). What I was doing was chopping off everthing after the second decimal place in all of my calculations using the function I mentioned. This, until now, had worked OK and all the totals had added up. Until I got the dreaded
2.30 resulting in 2.29.
Any ideas how I should tackle this problem?
Thanks for the reply,
Ted.
I've written a little function to remove everything after the 2nd decimal place for prices which is as follows: -
ReturnConverted Currency = (fix(iSterling *
session("Exchan geRate") * 100) / 100)
However, it sometimes returns incorrect values. i.e. Why does the following: -
response.write( FormatNumber((f ix(2.30 * 1 * 100) / 100) , 2))
or
response.write( FormatNumber((i nt(2.30 * 1 * 100) / 100) , 2))
return 2.29 ?
Any help would be greatly appreciated as I've been ripping my hair out for a few hours trying to solve this one.
Ted.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alan Bashy |
last post by:
Please, guys, In need help with this. It is due in the next week. Please,
help me to implement the functions in this programm especially the first
three constructor. I need them guys. Please, help me.
This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of
our text.
I have done Exercise 7 for you: Below you will find the ADT specification
for a string
of characters. It represents slightly more that a minimal string...
|
by: Jackson Yap |
last post by:
can someone kind enough to help me look at the attached html and js
file? Why is it that the javascript menu could not work at
www.apchosting.net but could work at
http://home.pacific.net.sg/~jacksony ? (the drop down bar could not work
at www.apchosting.net but can drop at home.pacific.net.sg. I suspect it
is a server problem but was told it is not possible, therefore assuming
it is a client script problem? the script works last time...
|
by: Craig Keightley |
last post by:
Please help, i have attached my page which worksin IE but i cannnot get the
drop down menu to fucntion in firefox. Any one have any ideas why?
Many Thanks
Craig
<<<<<<<<<<<<<<CODE>>>>>>>>>>>>>>>>
<html>
|
by: James Radke |
last post by:
Hello,
I have a multithreaded windows NT service application (vb.net 2003) that I
am working on (my first one), which reads a message queue and creates
multiple threads to perform the processing for long running reports. When
the processing is complete it uses crystal reports to load a template file,
populate it, and then export it to a PDF.
It works fine so far....
|
by: Michael D. Reed |
last post by:
I am using the help class to display a simple help file. I generated the
help file using Word and saving it as a single page Web page (.mht
extension). I show the help file with the following statement.
Help.ShowHelp(Parent:=Me, url:=Me.HELP_URL_PRE & Me.myWorker.HelpFile)
How do I get it to go away when the program exits? Now when I quit the
program that I called it form the help file is sill displayed. Is there a
way to get a handle...
| |
by: Rahul |
last post by:
Hi Everybody
I have some problem in my script. please help me. This is script file.
I have one *.inq file. I want run this script in XML files. But this
script errors shows . If u want i am attach this script
files and inq files. I cant understand this error. Please suggest me.
You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online.
Plz....Plz..Plz...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted
********************************************************
For this teeny job, please refer to:
http://feeds.reddit.com/feed/8fu/?o=25
|
by: Stef Mientki |
last post by:
I'm making special versions of existing functions,
and now I want the help-text of the newly created function to exists of
1. an extra line from my new function
2. all the help text from the old function
# the old function
def triang(M,sym=1):
"""The M-point triangular window. <== old help text
"""
....
|
by: Amali |
last post by:
I'm newdie in c programming. this is my first project in programming.
I have to write a program for a airline reservation. this is what i
have done yet. but when it runs it shows the number of seats as 0 and
the flight no. is also repeating. If any can tell why is this please
help me.
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
|
by: Bob |
last post by:
Hi,
Hope you can help me with this one. I'm at my wits end. I'm trying to
create an intelligent edit-box like the
excellent "Customer" one at the URL:
http://munich.schwarz-interactive.de/autocomplete.aspx
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |