Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently November 17th, 2024, 1:25 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: currency
PostPosted: October 17th, 2007, 3:32 pm 
Offline

Joined: May 24th, 2007, 11:02 am
Posts: 132
Location: UK - Wales - Ceredigion
Opus: illuminatus > Evolution
OS: Windows 10 Pro
System: i7 8GB RAM
How do I format the result of 0.5 to show as 50p ?


Top
 Profile Visit website  
 
 Post subject:
PostPosted: October 17th, 2007, 9:30 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 511
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
depends where??
if the 0.5 is contained in a variable, you simply insert the variable into a text box, and put a 'p' after it :-) <variable>p
you can also concatenate the variable with "p"
var1=var1+"p"

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: October 18th, 2007, 4:24 pm 
Offline

Joined: May 24th, 2007, 11:02 am
Posts: 132
Location: UK - Wales - Ceredigion
Opus: illuminatus > Evolution
OS: Windows 10 Pro
System: i7 8GB RAM
Thank you for your reply. I'm now sorted.

What I wanted:

0.1 to become 0.10
or
1 to become 1.00
or
1.1 to become 1.10


I found this script that may help others:

you will need two variables: ans and num

- num is your start number (eg 0.1)
- ans will be the answer (eg 0.10)

on a button I placed the following code:

Code:
round_decimals(num,2)


Then in the main code of the page I used:

Code:
function round_decimals(original_number,decimals){
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)}   /* calls pad_with_zeros function */

function pad_with_zeros(rounded_value, decimal_places){
    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
    if (decimal_location == -1){
      decimal_part_length = 0
      value_string += decimal_places > 0 ? "." : ""}
    else {
        decimal_part_length = value_string.length - decimal_location - 1}
    var pad_total = decimal_places - decimal_part_length
    if (pad_total > 0){
    for (var counter = 1; counter <= pad_total; counter++)
    value_string += "0"}
    return ans=value_string}


On my page I have a text box with:' £<ans> 'to show my result.


Top
 Profile Visit website  
 
 Post subject:
PostPosted: October 18th, 2007, 8:17 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 511
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
sorry--I misunderstood what you were asking, but now I see. An interesting solution.

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group