Working With Prices/Decimal Points

I've recently figured out how to perform calculations on values by assigning them to variables in a click function however I'm working with prices in my app and it seems difficult to get prices/decimal points to claculate properly. At the moment my app looks like this:-
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
private function getTotal():void{
var addon1Int:int = parseInt(addon1.text);
var addon1Float:Number = parseFloat(addon1.text);
var addon1Number:Number = new Number(addon1.text);
var addon2Int:int = parseInt(addon2.text);
var addon2Float:Number = parseFloat(addon2.text);
var addon2Number:Number = new Number(addon2.text);
var addon3Int:int = parseInt(addon3.text);
var addon3Float:Number = parseFloat(addon3.text);
var addon3Number:Number = new Number(addon3.text);
var addon4Int:int = parseInt(addon4.text);
var addon4Float:Number = parseFloat(addon4.text);
var addon4Number:Number = new Number(addon4.text);
var addon5Int:int = parseInt(addon5.text);
var addon5Float:Number = parseFloat(addon5.text);
var addon5Number:Number = new Number(addon5.text);
var quantityNumber:Number = new Number(quantity.value);
total.data = (addon1Number + addon2Number + addon3Number + addon4Number + addon5Number) * (quantityNumber);
]]>
</mx:Script>
<mx:Text id="addon1" text="5.99"/>
<mx:Text id="addon2" text="6.99"/>
<mx:Text id="addon3" text="8.99"/>
<mx:Text id="addon4" text="4.99"/>
<mx:Text id="addon5" text="3.99"/>
<mx:NumericStepper id="quantity"/>
<mx:Button label="Button" click="getTotal();"/>
<mx:Text id="total"/>
</mx:Application>
It works ok if the numbers in the text areas are whole numbers like 8 or 4 but if I use numbers like 02.99, 05.09 the result comes out a bit srange. For example the result of the numbers that I have in there now if I set the value to 2 in the numeric stepper is 61.900000000000006 when I know from using a real calculator it should be 61.9. Is there any way perhaps of rounding this code to the nearest decimal point so it appears as 61.90?
Are there any good tutorials that any of you know of when working with prices/decimal points in flex?

I've managed to find the solution for this - the currency formatter. If anyone's interested or has similar problems her's the code that solves it for me:-
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.formatters.NumberBaseRoundType;
private function getTotal():void{
var addon1Int:int = parseInt(addon1.text);
var addon1Float:Number = parseFloat(addon1.text);
var addon1Number:Number = new Number(addon1.text);
var addon2Int:int = parseInt(addon2.text);
var addon2Float:Number = parseFloat(addon2.text);
var addon2Number:Number = new Number(addon2.text);
var addon3Int:int = parseInt(addon3.text);
var addon3Float:Number = parseFloat(addon3.text);
var addon3Number:Number = new Number(addon3.text);
var addon4Int:int = parseInt(addon4.text);
var addon4Float:Number = parseFloat(addon4.text);
var addon4Number:Number = new Number(addon4.text);
var addon5Int:int = parseInt(addon5.text);
var addon5Float:Number = parseFloat(addon5.text);
var addon5Number:Number = new Number(addon5.text);
var quantityNumber:Number = new Number(quantity.value);
var total:Number = (addon1Number + addon2Number + addon3Number + addon4Number + addon5Number) * (quantityNumber);
totalAmount.text=currencyFormatter.format(total);
]]>
</mx:Script>
<mx:CurrencyFormatter id="currencyFormatter" precision="2" rounding="none" decimalSeparatorTo="." thousandsSeparatorTo="," useThousandsSeparator="true" useNegativeSign="true" currencySymbol="£" alignSymbol="left"/>
<mx:TextInput id="addon1" text="5.99"/>
<mx:TextInput id="addon2" text="06.99"/>
<mx:TextInput id="addon3" text="08.99"/>
<mx:TextInput id="addon4" text="04.99"/>
<mx:TextInput id="addon5" text="03.99"/>
<mx:NumericStepper id="quantity"/>
<mx:Button label="Button" click="getTotal();"/>
<mx:Text id="totalAmount"/>
</mx:Application>

Similar Messages

  • LSMW field with 5 decimal points

    Hi All,
    I need to pass a field in the LSMW with 5 decimal points.
    we cannot pass the data type as "PAC5". can any one suggest how this can be done in LSMW.
    Also, I am passing the currency key as USDN in the LSMW using Idoc method. But it is taking only as USD even though the length of the field is 5 chars. But I am able to acheive this if I manually post it as USDN.
    please suggest on the above 2 issues.
    Helpful answers will definitely be rewarded.
    Thanks in Advance,
    Asif Ali Khan

    hi khan,
    see the below link
    http://www.abapcode.sapbrainsonline.com/2008/03/write-output-formatting-options-abap.html
    http://www.abapcode.sapbrainsonline.com/2008/03/types-abap-keyword.html
    sapabap.iespana.es/manuales/pdf/lsmw.pdf
    abapprogramming.blogspot.com/2008/03/sap-abap-syntax-for-assign.html - 122k
    abapprogramming.blogspot.com/2008/03/sap-abap-syntax-for-assign.html - 122k
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/90cef248-29e0-2910-11bb-df8dece7e22c
    thanks
    karthik

  • South America localization with comma decimal points

    Hello All:
        I am doing a simple division on a formatted search. However it is south america localization and it has the comma as decimal point instead of period. If I just do value 1 / value 2 it give me error message. if I replace , and then cast to numeric and then divide it works. But put in a trigger by formatted search it comes out as a wrong monetary value. The UDF for the FS is a quantity value. Not monetary!
        How does anyone do normal division and multiple with South America localization?
        Thank you for all the help!

    The field itself is actually a UDF of type Quantity. So using the quantity select $[$38.11.0]/$[rdr1.U_myfield]
    I suppose for checks you can just divide quantity by price or something! But it doesn't seems  to work for me!

  • My quantity is showing with a decimal point and two spaces

    When people are entering a quantity of 1 it is showing as 1.00.  It is confusing my users because they think this is a price.  How can I get rid of the decimal point and two spaces? 

    Hi,
    I am not able to reproduce this problem with a number field.  Are you using this field as a payment-quantity field?.  If so, please check that the Quantity in your payment setting is linked the the right field.
    We can do a quick test: create a new form from scratch, add one textfield, then on the field property panel select Type=number.
    Select Test tab and click on the Test Web Form button
    Enter a number and commit --> check if you get the decimal point and the spaces.
    If you still have problem with this, let me know
    Thanks,
    Lucia

  • Working with a center point

    How is the Center Point used in CS5 when working with transformation tools? What types of things can be done with it?
    Thanks.

    When transforming one can just drag the Reference Point from its 
    position in the center of the transformation-rectangle (it might be 
    hard to see depending on the image).
    Or it you want to have it at one of the corners or middles of sides 
    you can switch it in the Options bar.
    As to the benefits: When one wants to scale radially(alt-shift) from 
    another than the oroginal center-position this allows for such a 
    transfromation – for example if one has to recreate a lores-montage 
    with high-res data it can be easier to line up one single element of a 
    semi-transparent SO with the layout and then scale from that point 
    until congruence is achieved.

  • Display unsigned value (battery voltage) = 8134 formatted with a decimal point: 8.134

    How can I display an unsigned value such as 8134 with an "implied" decimal point e.g. 8.134 without dividing by 1000? Is there a format code that will do this? I have Student Version 8.2.1. Many thanks

    It seems silly to force such an arbitrary restriction. A division is cheap, why son't you want to do it???
    Of course you could assign a unit such as V and then set the units to kV for the display.
    I would go with the division!
    Message Edited by altenbach on 11-18-2007 04:58 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    DivideBy10.png ‏5 KB

  • How do reward certificates work with price adjustments?

    I purchased an item for $50 using $40 reward certificate with the rest on my credit card. That item is now on sale for $20 less and it has only been 6 days (I am in the return period). How will it work since the returned amount will be more than what was charged to my card, will I just get the reward points back?

    Hello darkk88,
    That is a great question!  If you meet the terms of our Price Match Guarantee, then you will definitely have some points that are returned to your My Best Buy™ account.  There is a possibility the portion that was charged to your credit card could be refunded; however, it is more likely that points will be returned since a majority of the purchase was paid for with certificates.  Let me know if you have any other questions. : smileyhappy:
    Best Buy Price Match Guarantee
    I hope you have a fantastic day, and thank you for connecting with us on the forum!
    Derek|Social Media Specialist | Best Buy® Corporate
     Private Message

  • Font size with a decimal point

    I've been making a Safety Manual for a company that I am working for and for the past month everything has been going smoothly, for the most part. That is until today. As usual I am changing my font size and it all of the sudden won't let me change the size,
    I put my cursur there and it is black and makes a beep (the beep that means you are doing something wrong). Please help me, as I'm on my last 3 pages.
    Thanks,
    Chantal

    Hi,
    Was the decimal number created by yourself? If not, please try to paste the number in notepad first, then copy paste the numbers to your document.
    You mentioned, everything was fine till today. Was there any changes in your OS or office?
    Also do you mind to share me a copy (keep just the decimal part which you can’t change font size) to:
    [email protected]? So I can test it from my side. Please use thread link or the subject of this post as mail subject.
    Thank you.

  • Sales doc copy control not working with price condition

    Here's the situation.
    For OR sales document I have  Procedure ZSALES and price conditions Z001
    For a QT Sales document I have Procedure ZQUOTE which does not have a Z001 condition in that procedure.
    If I create an OR (with the proper customer / matieral) the Z001 populates, based on it's defined record.
    If I then create another OR with reference to the original OR, the Z001 populates with no problem.
    Up to now everything's fine, now here's the probem......
    If I create an OR with reference to a QT, the Z001 does not populate in the OR order.I know there is no Z001 in the QT for it to copy from, but if I do [New Pricing] in the order it still does not come in.(I've tried [new Pricing] with Pricing type A..G)
    I have found OSS Note 413066, but this is in reference to 46c systems. we are on ECC 6.0
    any ideas ?

    Hi Bill,
    If PP assigned for both are different it's not going to populate field even if you are redertermining price, since it would be following the PP of Quotation (ZQUOTE), not Sales Order (ZSALES) because it's gonna copy the elements of that PP in order. Are your PP assigned are same or different?
    Hope this will answer your query
    Regards
    SD

  • Reports with 2 decimal points

    Dear Experts
               I want to increase the decimal places of INR from 2 Decimal places to 6 Decimal places,But i want the standard SAP reports to come in 2 decimal places for INR even after changing to 6 decimal places.please Give me solution to this request..

    Hi,
                        Actually what others said is right,but u can use the formula round and round it off to Two digits.
    Example: Field name F_012
    Insert a new field -->select source type -->Formula
    and in the empty space Round(F_012,2)......It will give the cost or rate in two decimal places.
    But u have to do this in every report.
    Regards,
    Shyam

  • Generic delta not working with '0calday' change pointer

    I have created a generic datasource based on a database view and extracted data with afull load infopackage into BI. Then, I configured the generic delta with a date field and 0calday type. Set the safety interval of 1 day as a lower limit. Saved the datasource in R/3 and Replicated and activated the datasource in BI. Done some changes to a record in R/3.
    After that, I created an Init delta infopackage (with data) and extracted the data with the same number of records as extracted in the full load. Note that all these were done on the same day.
    If I have done something wrong by doing it on a same day, I should get 0 records.
    Why did I get the same data with a delta init package? I wonder the generic delta is configured correctly or not? Please tell me where I have gone wrong. Thanks..

    Hi Shiva,
    While running the delta init, you have option of without data transfer and, with data transfer.
    I am sure, you used with data transfer and thats why  got all those records same as full load.
    U can use different options like.
    1. DO the init without data transfer and then do the full load, and then run delta everyday for delta records
    2. Do the init with data transfer then no need to do the full load and the subsequent delta will take care day onwards,
    I guess your are good to do the delta load by tomorrow.
    Thank-You.
    Regards,
    Vinod

  • Strange- A 1" horizontal strip on the screen (which includes the tabs + 0.5cm above and below) does not work with the mouse pointer, only with firefox

    The mouse wont click anywhere over a 1" strip that includes the area where the tabs are lined, and extends 0.5cm above and below this. So, to open or close a tab I can only use Ctrl T or Ctrl W respectively. And, for ex, I cannot click on the top most line on Facebook (which has the Home, messages, news feeds options etc) or that of Twitter, and so on. I have used Mozilla Firefox all my life and this has never happened before. I don't have this problem with any other browser like Internet explorer or Google Chrome. I find it very strange.

    Both the Yahoo! Toolbar extension and the Babylon extension have been reported to cause this issue. Disable or uninstall those add-ons.
    * https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • How do I enter data in excel with a specified number of decimal points?

    I have several inputs that are being written into excel using the "Write to Spreadsheet file" vi. One of my inputs only writes to excel with 3 decimal points. I would like it to have four, how do I change this?

    Pop-up on the top input to the "Write to Spead...." labled "Format".
    Chnage it from the default of "%.3f" to "%.4f"
    Ben
    Ben Rayner
    Certified LabVIEW Developer
    www.DSAutomation.com
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Problems with Illustrator CS6 not accepting stroke weights with decimal points

    So I have been using Illustrator for almost 10 years and have never run into this one. When enter a stroke weight on a line with a decimal point like .25 or 4.5 is keeps rounding the number up. For example I enter 0.75 and it makes it 1 point or I enter 5.5 and it makes it 6 point. Whether I enter the number manually or pick from the drop down (0.25, 0.5 or 0.75) it keeps rounding my strokes to even numbers. How did I do and how do I fix it?

    Thanks from me too! Was also very frustrated by this.

  • PDF Forms: problem with keypad "decimal dot" when filling "number" fields

    Ok, here's my problem :
    I've created a form with fields. My client want to input in those fields amount of money. So I've created fields formatted with the "Number" category. 2 decimals, "1234,56" separator style, not currency symbol. So far, so good!
    When testing out the form, here's what happening :
    On the computer that I've created the form (iMac, Acrobat Pro and Reader, french canadian keyboard layout and system)
    Using the keypad, I can input numbers, with the "decimal point" from the keypad no problem.
    But when the client is trying to to the same on his PC (and the same is happening with my PC at home, Acrobat Pro 9.2, french canadian keyboard layout and system), I CAN'T use the "decimal point" keypad key to input numbers (like 43,25). It's just not working (error sound). I can however use the "dot" on the keyboard near the "M" key, but the client don't want to do that.
    Why is it working on the Mac, but not on the PC's!?
    So far, the only workaround that I've found is to set the "money" fields categories to "none" instead of "number.

    It is a little bit tricky, but you might have to add your own formatting handler. You would proceed as follows:
    1. Set the Format to "none".
    2. Add the following script to a Custom Keystroke event:
    if (event.change.length > 0 && event.willCommit == false) {event.change = event.change.replace(/\,/gim, ".") ;
    3. Add the following script to a Custom Format event:
    event.value = event.value.toString().replace(/\./gim, ",") ;
    And that should take care of the situation.
    Note that i have not tested the scripts, and there may be a chance for bugs.
    The advantage of this solution is that internally, you will have the correct format for a number, so that calculations will be correct.
    Hope this can help.
    Max Wyss.

Maybe you are looking for