Great Ideas. Always Flowing.

We are not happy until you are happy. Client satisfaction guaranteed. Whatever your needs and requirements, we have the skills and resources for the job!

Quick login...


Or... now make it easy with Facebook Integration
Connect via Facebook



Top Sellers

Frustrated over the lack of customization for your user's registration fields? Dynamically setup your DNN Portal with custom registration fields, layout, questions, and other core integration options......

Ultra Video Gallery is a brother product of Ultra Media Gallery, UVG allows you to upload videos in various format and automatically encode them to flv or H264 format, you also can add videos from internet or record live videos from your webcam.

Build high performance, completely customizable data-entry forms and views driven by your DNN and external databases. New built-in tools make it a snap to quickly create data entry forms, data views, and even database tables. Plus, add your own HTML, CSS, Javascript, SQL commands, stored procedures,

The most advanced DotNetNuke shopping cart on the planet. Easy to use e-Commerce, Secure Shopping Cart Software and SEO friendly. B2C / B2B Ecommerce Sites.

One stop solution for events calendar and events registration! FREE DOWNLOAD is available now!

Truncate to two decimals.
Last Post 12-02-2010 07:55 AM by Ryan Bakerink. 14 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Andy ThomasUser is Offline
skipping stones
skipping stones
Posts:13
Avatar

--
01-24-2009 09:04 PM

    Hi! I have a form where I multiply quantity by rate. If the rate is 2.99 and a customer purchases 99 items, the total is showing as 296.009200000001. Can anybody help me how I can truncate that total to two decimals, like 296.01?

     

    Thanks, Andy

    Chad NashUser is Offline
    Posts:5260
    Avatar

    --
    01-27-2009 10:22 AM
    Hi Andy... There are a few function calls that are added into the main JavaScript file of Dynamic Forms so you might try that. Such as formatCurrency(value) and also you might even try value.toFixed(2) and that should show two decimals. If you setup a page on Beta Springs with your implementation (login as host with a pw of dnnhost) I would be happy to review it and see what function call could be used there as well.

    Thanks,


    -Chad
    Eric BautistaUser is Offline
    Posts:27
    Avatar

    --
    08-04-2009 11:54 AM

    Hi Andy & Chad,

     

     were you able to solve this issue? We've tried using the value.toFixed(2) without success. Is there an example in betasprings we might take a look at? Thanks.

    David ToUser is Offline
    river guide
    river guide
    Posts:2719
    Avatar

    --
    08-05-2009 06:21 AM
    HI, I found this off Google, it may work for you:
    function fixAtTwo(anynum)
    {
    var numStr=anynum.toString();
    var decPos = numStr.indexOf(".");
    if ( decPos == -1 )
    return numStr + ".00";
    else
    {
    // add two zeros to get at least two digits at the
    // end of the string in case it ends at the decimal
    numStr += "00";
    return numStr.substr(0,decPos+3);
    }
    }
    -- David
    David ToUser is Offline
    river guide
    river guide
    Posts:2719
    Avatar

    --
    08-05-2009 08:25 AM
    Also, perhaps try this out as well:
    function toTwoDecimals(n) {
    var s = "" + Math.round(n * 100) / 100
    var i = s.indexOf('.')
    if (i < 0) return s + ".00"
    var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
    if (i + 2 == s.length) t += "0"
    return t
    }
    -- David
    Eric BautistaUser is Offline
    Posts:27
    Avatar

    --
    08-05-2009 12:13 PM

    Hi Dave,

     

     we were able to make it work using the following formula:

     

    $(field_name)=fixAtTwo($(f_Total)*1.17)

     

    Thanks!

    DougUser is Offline
    wading in the water
    wading in the water
    Posts:15
    Avatar

    --
    11-16-2010 05:45 PM
    Eric,
    Where did you put the formula to get it to work? I see the same function as above named "totwodecimals" included in the javascript file in Dynamic Forms, but when I put

    toTwoDecimals($(ShortFieldName))

    in the client side event section of my label field that I want to truncate it's not taking effect. I'm pulling money fields from SQL into DF label fields (via SQL Binding) and they are all coming in with 4 decimal places.

    Thanks in advance,
    Doug
    ChuckUser is Offline
    river guide
    river guide
    Posts:157
    Avatar

    --
    11-17-2010 04:44 AM
    Posted By Doug on 11/16/2010 7:45 PM
    Eric,
    Where did you put the formula to get it to work? I see the same function as above named "totwodecimals" included in the javascript file in Dynamic Forms, but when I put

    toTwoDecimals($(ShortFieldName))

    in the client side event section of my label field that I want to truncate it's not taking effect. I'm pulling money fields from SQL into DF label fields (via SQL Binding) and they are all coming in with 4 decimal places.

    Thanks in advance,
    Doug
     Hi Doug,

    Do you want to truncate the decimals before it shows up on the DF?  If so, you may want to do the truncating in you SQL binding assuming you are doing this via a Stored Procedure.  Here is a link that may give you some guidance.

    http://stackoverflow.com/questions/...sql-server

    Or if you wish for the USER to override it, in the client side use this code instead:

    $(ShortFieldName) = toTwoDecimals($(ShortFieldName));

    Note:
    You will not see the truncate happen as they type, but when the textbox loses focus, it will truncate to two decimals.  Also, it will round accordingly 
    e.g.
    1.999 => 2.00
    1.556 => 1.56

    Hope this helps.
    -Chuck


    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    11-17-2010 07:35 AM
    Hello Chuck,

    Thank you for your contribution of knowledge and reaching out to help others in the forum threads.

    This helps us spend more time in other area such as development and enhancements.

    Thanks again.

    Ryan
    DougUser is Offline
    wading in the water
    wading in the water
    Posts:15
    Avatar

    --
    11-17-2010 10:02 AM
    Chuck,
    Thanks for the response. I am indeed using a sql binding via a stored proc, and modified my query from (select *) to (select Round(ColumnA,2,1), X, Y, Z....) however this did not fix it. Also I wanted to point out that even doing a select against my column directly in SQL returns just 2 decimals, so I don't think it is in SQL. So then I went the next approach of the client side event with the function and unfortunately it made no difference either. However, I did confirm that when making the field a text box (as opposed to a label), the data initially shows up with 4 decimals, but like you said if I click into the field and then out of it, the function gets called and it works great. Any way to make the field show up already trimmed so that I can continue to use all my labels with money fields? Meanwhile I'm going to look at other avenues such as displaying the fields as sentences like displayed in the demos (i.e. "Your total is: $100.00) because I'd also like control over the look and feel of the text data once it's binded to the form.

    Thanks again,
    Doug
    DougUser is Offline
    wading in the water
    wading in the water
    Posts:15
    Avatar

    --
    11-17-2010 05:01 PM
    Solved this by modifying my SQL Bind stored procedure to convert the money columns to varchar() on retrieval as such:

    cast([ItemPurchPrice] as varchar(10)) as 'ItemPurchPrice'


    -Doug
    ChuckUser is Offline
    river guide
    river guide
    Posts:157
    Avatar

    --
    11-19-2010 07:29 AM
    Posted By Doug on 11/17/2010 7:01 PM
    Solved this by modifying my SQL Bind stored procedure to convert the money columns to varchar() on retrieval as such:

    cast([ItemPurchPrice] as varchar(10)) as 'ItemPurchPrice'


    -Doug
     Thanks for the followup.  I also have found a solution when a user needs to input a decimal value that it prevents the user from extending it out to whatever decimal placement you define.  Basically you have to redefine your Questionfield name to invoke a onkeypress and onkeyup client side script.  If you are interested take a look at this link for further explanation on how this script works.

    http://www.mredkj.com/tutorials/validate2.html

    If you need a sample of it working, just give me a holler and I can post it on their betasprings website.

    -Chuck

    DougUser is Offline
    wading in the water
    wading in the water
    Posts:15
    Avatar

    --
    11-20-2010 03:19 AM
    Pretty slick stuff Chuck. It's kind of a "nice to have" at this point and I tried to implement it but after about a half hour couldn't get it working. If you get a chance I'd be happy to look at your example if you posted it on betasprings. Thanks again for your time and support.

    -Doug
    ChuckUser is Offline
    river guide
    river guide
    Posts:157
    Avatar

    --
    11-22-2010 12:23 PM
    Posted By Doug on 11/20/2010 5:19 AM
    Pretty slick stuff Chuck. It's kind of a "nice to have" at this point and I tried to implement it but after about a half hour couldn't get it working. If you get a chance I'd be happy to look at your example if you posted it on betasprings. Thanks again for your time and support.

    -Doug
    Doug,
     I posted a working example on their test site at:
    http://www.betasprings.com/Dynamic-...fault.aspx

    In the Custom Javascript Files, you will notice I added 3 function between the section I called "NEW FUNCTIONS"

    You will see how I altered their 2 javascript functions to work with DataSprings Form.  As you may notice in the CLIENT SIDE events that you must also rename your questions and append the 'onkeypress_onkeyup' to invoke Data Springs Forms respective client side actions.  Also, in the CLIENT SIDE events, I am passing the QUESTION $(SHORTNAME_FieldID) too.

    Also Note, when I added the GetTotal function, it has to sandwich between the two JS functions being called.  If its out of order, calculations wont work.

    Hope this will all make sense when you take a look.

    -Chuck

    Ryan BakerinkUser is Offline
    river guide
    river guide
    Posts:1900
    Avatar

    --
    12-02-2010 07:55 AM
    Hello Doug,

    Please let us know how Chuck's example worked for you, if you have any further questions please let us know or let Chuck know .

    Thanks,

    Ryan
    You are not authorized to post a reply.


     
     

    Join our mailing list...

    Get current news and events the easy way
    Subscribe Me

    Recent Blogs...

     
    Copyright 2005 - 2011 by Data Springs, Inc.
     
  • film izle
  • 720 izle
  • film
  • sinema izle
  • film makinesi
  • T�rk�e dublaj film
  • film izle
  • film izle
  • baglan film izle
  • sinema izle
  • 1080 film izle
  • film mercegi