Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
honky dong
Sep 2, 2011

Maluco Marinero posted:

Can you access the HTML for the survey? Using HTML5 attributes will cover most of the modern browsers. That I guess depends on what you expect your users' browsers to be. You have analytics on this from previous surveys?
code:
<input type="text" placeholder="Click here to begin typing...">
Otherwise you'll have to have a search around. There are libraries for it that work well cross browser, but you might not be able to use them yeah?

I just tried this and it didn't work. Here's a screenshot of the editing box to show what I'm working with:

Adbot
ADBOT LOVES YOU

Video Nasty
Jun 17, 2003

Borderview posted:

I just tried this and it didn't work. Here's a screenshot of the editing box to show what I'm working with:


Try this:
code:
<input type="text" placeholder="Hello" value="Hello"  onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" >
http://jsfiddle.net/66P5r/
This should work in place of non-HTML5 browsers.

Video Nasty fucked around with this message at 18:51 on Feb 2, 2013

honky dong
Sep 2, 2011

Jake Blues posted:

Try this:
code:
<input type="text" placeholder="Hello" value="Hello"  onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" >
http://jsfiddle.net/66P5r/
This should work in place of non-HTML5 browsers.


Hmm... that didn't work either. Although, the example on that site is exactly what I'm after. I just dug up this code in their knowledge base that seems to work (:doh: why didn't I look there first!?):

code:
var InputId = $("QR~"+this.questionId);
    var Text = "Click here to type word. . . "; 
    InputId.value = Text;
     
    InputId.onclick = clear;
    InputId.onblur = repopulate;
      
    function repopulate() {
    if (InputId.value == "")
    {
      InputId.value= Text;
    } 
    }
     
    function clear() {
    if (InputId.value == Text)
    {
      InputId.value= "";
    }
    
Problem with this is that the text is black instead of gray. Is there an easy way to change that? Many thanks. I really appreciate the help.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Borderview posted:

Hmm... that didn't work either. Although, the example on that site is exactly what I'm after. I just dug up this code in their knowledge base that seems to work (:doh: why didn't I look there first!?):

code:
var InputId = $("QR~"+this.questionId);
    var Text = "Click here to type word. . . "; 
    InputId.value = Text;
     
    InputId.onclick = clear;
    InputId.onblur = repopulate;
      
    function repopulate() {
    if (InputId.value == "")
    {
      InputId.value= Text;
    } 
    }
     
    function clear() {
    if (InputId.value == Text)
    {
      InputId.value= "";
    }
    
Problem with this is that the text is black instead of gray. Is there an easy way to change that? Many thanks. I really appreciate the help.

Can you edit the CSS (styles/style sheets) of the site? That could be a better solution. If not, this should work (I assume that $ is just document.getElementById, juding from the usage of InputId)

JavaScript code:
    
function repopulate() {
    if (InputId.value == "")
    {
      InputId.value= Text;
	InputId.style.color = "silver";
    }

    function clear() {
    if (InputId.value == Text)
    {
      InputId.value= "";
	InputId.style.color = "black";
    }
}

honky dong
Sep 2, 2011

Wheany posted:

Can you edit the CSS (styles/style sheets) of the site? That could be a better solution. If not, this should work (I assume that $ is just document.getElementById, juding from the usage of InputId)

JavaScript code:
    
function repopulate() {
    if (InputId.value == "")
    {
      InputId.value= Text;
	InputId.style.color = "silver";
    }

    function clear() {
    if (InputId.value == Text)
    {
      InputId.value= "";
	InputId.style.color = "black";
    }
}

Awesome. That worked! Thanks so much. Yeah, there is an option to "add Custom CSS" or to pull it from an external website. That probably goes way beyond my already non-existent skills, though. At some point I'm planning on taking a class on this stuff just so I understand the basics of it.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Borderview posted:

Awesome. That worked! Thanks so much. Yeah, there is an option to "add Custom CSS" or to pull it from an external website. That probably goes way beyond my already non-existent skills, though. At some point I'm planning on taking a class on this stuff just so I understand the basics of it.

Well, here are the basics for your current task:
CSS code:
input {
	color:silver;
}
input:focus {
	color:black;
}
And remove the javascript I gave you.

This doesn't work on IE below 8, but gently caress'em.

honky dong
Sep 2, 2011

Wheany posted:

Well, here are the basics for your current task:
CSS code:
input {
	color:silver;
}
input:focus {
	color:black;
}
And remove the javascript I gave you.

This doesn't work on IE below 8, but gently caress'em.

Ah.. way easier. Thanks!

Praxis Prion
Apr 11, 2002

The sky is a landfill.
Pillbug
Hey, I use a display screen on an HTPC to display media information for winamp with the plug-in browseamp. I'm in the process of building a control interface, but I'm running into some difficulty with the javascript. I'm attempting to have the song position and time remaining called and displayed in text without the need to refresh the page. So far I have:

code:
function UpdateTime() {
 	if(SecondsRemain > 0) 	{
 		SecondsRemain--;
 		TrackPos++;
	} else if (Status=="play") {
		window.setTimeout("sendCommand('refresh')",1000);
		parent.window.setTimeout("refreshPlaylist() ",1000);
	}
 	document.getElementById("progressBar").width = Math.max(1,TrackPos/TotalSeconds*document.getElementById("progressBarCell").width-4) ;
	//alert(SecondsRemain,TrackPos);
	if (Status=="play") window.setTimeout("UpdateTime()",1000);
}
which updates the length of the progress bar. I'm trying to call:

code:
<div id="timers">
<table border="0" cellpadding="0" cellspacing="0" width="524">
	<tr>
		<td id="TotalSeconds"><#SongLengthMin>:<#SongLengthSec></td>
		<td id="TrackPos"><#SongPositionMin>:<#SongPositionSec></td>
		<td id="SecondsRemain">-<#SongRemainMin>:<#SongRemainSec></td>
	</tr>
</table>
</div>
and have the position and song time remaining updated in real-time in text. I'm pretty new to javascript, so let me know if there is additional information from the code needed. Appreciate it!

thepedestrian
Dec 13, 2004
hey lady, you call him dr. jones!
I'm working on an app where the user traverses a force graph that is generated from a web search query. Is D3.js the best option for a dynamically created force graph? It seems most of the D3 examples are static data tables loaded in on initialization rather than being added over time. In this app the graph is primarily used as a navigation method rather than a data visualization.

I'm having trouble moving beyond example code because I don't totally grasp the functionality since it seems like D3 can be used to make 1000 different types of crazy graphs. Is there a better, force graph specific option out there?

LeCron James
Apr 1, 2011

Jim Jones posted:

Hey, I use a display screen on an HTPC to display media information for winamp with the plug-in browseamp. I'm in the process of building a control interface, but I'm running into some difficulty with the javascript. I'm attempting to have the song position and time remaining called and displayed in text without the need to refresh the page. So far I have:

code:
function UpdateTime() {
 	if(SecondsRemain > 0) 	{
 		SecondsRemain--;
 		TrackPos++;
	} else if (Status=="play") {
		window.setTimeout("sendCommand('refresh')",1000);
		parent.window.setTimeout("refreshPlaylist() ",1000);
	}
 	document.getElementById("progressBar").width = Math.max(1,TrackPos/TotalSeconds*document.getElementById("progressBarCell").width-4) ;
	//alert(SecondsRemain,TrackPos);
	if (Status=="play") window.setTimeout("UpdateTime()",1000);
}
which updates the length of the progress bar. I'm trying to call:

code:
<div id="timers">
<table border="0" cellpadding="0" cellspacing="0" width="524">
	<tr>
		<td id="TotalSeconds"><#SongLengthMin>:<#SongLengthSec></td>
		<td id="TrackPos"><#SongPositionMin>:<#SongPositionSec></td>
		<td id="SecondsRemain">-<#SongRemainMin>:<#SongRemainSec></td>
	</tr>
</table>
</div>
and have the position and song time remaining updated in real-time in text. I'm pretty new to javascript, so let me know if there is additional information from the code needed. Appreciate it!

So you're wondering how to change text through DOM?

If your HTML is like this:
code:
<div id="timers">
<table border="0" cellpadding="0" cellspacing="0" width="524">
	<tr>
		<!-- The - are just placeholders so we don't have to create a text node -->
		<td id="TotalSeconds">-</td>
		<td id="TrackPos">-</td>
		<td id="SecondsRemain">-</td>
	</tr>
</table>
</div>
You can then set the text node of each column by finding the ElementID you want, then changing the data in its child text node.
code:
document.getElementById("TotalSeconds").childNodes[0].data = "2:45" 
Which will change the text node of the node.

LeCron James fucked around with this message at 18:51 on Feb 4, 2013

Praxis Prion
Apr 11, 2002

The sky is a landfill.
Pillbug

LeCron James posted:

So you're wondering how to change text through DOM?

If your HTML is like this:
code:
<div id="timers">
<table border="0" cellpadding="0" cellspacing="0" width="524">
	<tr>
		<!-- The - are just placeholders so we don't have to create a text node -->
		<td id="TotalSeconds">-</td>
		<td id="TrackPos">-</td>
		<td id="SecondsRemain">-</td>
	</tr>
</table>
</div>
You can then set the text node of each column by finding the ElementID you want, then changing the data in its child text node.
code:
document.getElementById("TotalSeconds").childNodes[0].data = "2:45" 
Which will change the text node of the node.

Okay so I have:

code:
<div id="timers">
<table border="0" cellpadding="0" cellspacing="0" width="524">
	<tr>
		<td id="TotalSeconds">-</td>
		<td id="TrackPos">-</td>
		<td id="SecondsRemain">-</td>
	</tr>
</table>
</div>
<script type="text/javascript">
document.getElementById("TotalSeconds").childNodes[0].data = "<#SongLengthMin>:<#SongLengthSec>";
document.getElementById("TrackPos").childNodes[0].data = "<#SongPositionMin>:<#SongPositionSec>";
document.getElementById("SecondsRemain").childNodes[0].data = "<#SongRemainMin>:<#SongRemainSec>"
</script>

and it does update with the proper times, however, I'm trying to have these elements count as timers (and reverse for the song time remaining) and update in real-time without needing to refresh the page. Also, just to mention, the browseamp plugin hosts a server which recognizes commands such as <#SongLengthMin> and outputs the data in text.

Edit: Or I need to have the js code which outputs for example <#SongPositionMin> refresh every second without refreshing the page.

Praxis Prion fucked around with this message at 22:12 on Feb 4, 2013

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Jim Jones posted:

Okay so I have:

code:
<div id="timers">
<table border="0" cellpadding="0" cellspacing="0" width="524">
	<tr>
		<td id="TotalSeconds">-</td>
		<td id="TrackPos">-</td>
		<td id="SecondsRemain">-</td>
	</tr>
</table>
</div>
<script type="text/javascript">
document.getElementById("TotalSeconds").childNodes[0].data = "<#SongLengthMin>:<#SongLengthSec>";
document.getElementById("TrackPos").childNodes[0].data = "<#SongPositionMin>:<#SongPositionSec>";
document.getElementById("SecondsRemain").childNodes[0].data = "<#SongRemainMin>:<#SongRemainSec>"
</script>

and it does update with the proper times, however, I'm trying to have these elements count as timers (and reverse for the song time remaining) and update in real-time without needing to refresh the page. Also, just to mention, the browseamp plugin hosts a server which recognizes commands such as <#SongLengthMin> and outputs the data in text.

Edit: Or I need to have the js code which outputs for example <#SongPositionMin> refresh every second without refreshing the page.

code:

//You could snag the times using something like this

var duration = parseInt("<#SongLengthMin>", 10) * 60 + parseInt("<#SongLengthSec>", 10);
var elapsed = parseInt("<#SongPositionMin>", 10) * 60 + parseInt("<#SongPositionSec>", 10);
var remaining = duration - elapsed;

//Then set up your update function

var durationElement = document.getElementById("TotalSeconds").childNodes[0].data;
var posistionElement = document.getElementById("TrackPos").childNodes[0].data;
var remainingElement = document.getElementById("SecondsRemain").childNodes[0].data;

function secondsToMinSec(seconds){
	return (seconds / 60).toString() + ':' + (seconds % 60).toString();
}

function updateTimes(){
	durationElement = secondsToMinSeconds(duration);
	positionElement = secondsToMinSeconds(position);
	remainingElement = secondsToMinSeconds(remaining);
	duration -= 1;
	position += 1;
	remaining = duration - position;
}

//And then use setInterval to run it every second
setInterval(updateTimes, 1000);
//And run it on load
updateTimes();
Untested; may require some assembly; support for hour+ long tracks is left as an exercise for the reader

Bobbin Threadbear
May 6, 2007

Learning JS, so heres my amateur view. If I understand correctly, the the script will:

Page refreshes for every song
Displays remaining time, total song length and current time position
Current time and remaining time are updated AJAX style
Web server fills in template variables then sends the data to the browser

So what I would do, is at the start of your script, set a variable that holds the entire song length in seconds (<#SongTotalSec>) and then set the current time (<#SongPositionMin> * 60 + <#SongPositionSec>) and set your remaining time.
code:
totalSongLength = parseInt(<#SongTotalSec>, 10);
currentTime = parseInt("<#SongPositionMin>", 10) * 60 + parseInt("<#SongPositionSec>", 10);
remainingTime = totalSongLength - currentTime;
Then I'd create a function that increments the currentTime and decrements the remaining time every 60 seconds (1000 ms) and then updates the DOM

code:
function updateCurrentTimes() {
    remainingTime--;
    currentTime++;

    updateDom();
}

function updateDom() {
    var currentFormattedTime = Math.floor(currentTime / 60) + ':' + currentTime % 60;
    var remainingFormattedTime = '-' + Math.floor(remainingTime / 60) + ':' + remainingTime % 60;

    document.getElementById("TrackPos").childNodes[0].data = currentFormattedTime;
    document.getElementById("SecondsRemain").childNodes[0].data = remainingFormattedTime;
And then run that function every 1s and set the page to reload after remainingTime has passed

code:
setInterval(updateCurrentTimes, 1000);
setTimeout(reload, remainingTime * 1000);
The length of the song shouldn't change, so that can just be statically set on a page load.

With this approach, you can set your HTML to how it was
code:
<div id="timers">
<table border="0" cellpadding="0" cellspacing="0" width="524">
	<tr>
		<td id="TotalSeconds"><#SongLengthMin>:<#SongLengthSec></td>
		<td id="TrackPos"><#SongPositionMin>:<#SongPositionSec></td>
		<td id="SecondsRemain">-<#SongRemainMin>:<#SongRemainSec></td>
	</tr>
</table>
</div>
So that right off the bat the page is loaded with the correct values and it will feel smooth. No reason to manage the song length with DOM.

Bobbin Threadbear fucked around with this message at 23:40 on Feb 4, 2013

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



That'd probably work fine for you. You could also have a condition in your time update function that reloads the page when it notices that the time has run out.

You should also make sure the server is inserting time without zeros padding it because 09 will be interpreted as octal. That's why I had it parsing strings and forcing base 10 - I'm just used to being defensive about number formats in JS.

Bobbin Threadbear
May 6, 2007

Munkeymon posted:

That'd probably work fine for you. You could also have a condition in your time update function that reloads the page when it notices that the time has run out.

You should also make sure the server is inserting time without zeros padding it because 09 will be interpreted as octal. That's why I had it parsing strings and forcing base 10 - I'm just used to being defensive about number formats in JS.

Yeah, this is important. Always set your parseInts base! I just fixed that, thanks.

Praxis Prion
Apr 11, 2002

The sky is a landfill.
Pillbug
Bobbin - I got your script to work, but I have a question. Assuming a song is less than 10 minutes long, how would I add a 0 in the tens position for elapsed and remaining time, as well as the tens position in seconds. In other words, I need a continuous ##:## format for time elapsed and time remaining like a clock would display.

Thanks for the help guys!

Praxis Prion fucked around with this message at 01:53 on Feb 5, 2013

Bobbin Threadbear
May 6, 2007

You could do something like

code:
function padTime(time) {
    if(time < 10) {
        return '0' + time;
    }
    return time;
}

var currentFormattedTime = padTime(Math.floor(currentTime / 60)) + ':' + padTime(currentTime % 60);
It's certainly not very flexible, but it should do its job just fine for something like this.

Praxis Prion
Apr 11, 2002

The sky is a landfill.
Pillbug

Bobbin Threadbear posted:

You could do something like

code:
function padTime(time) {
    if(time < 10) {
        return '0' + time;
    }
    return time;
}

var currentFormattedTime = padTime(Math.floor(currentTime / 60)) + ':' + padTime(currentTime % 60);
It's certainly not very flexible, but it should do its job just fine for something like this.

Okay great! So I have

code:
function updateDom() {
    var currentFormattedTime = padTime(Math.floor(currentTime / 60)) + ':' + padTime(currentTime % 60);
    var remainingFormattedTime = '-' + padTime(Math.floor(remainingTime / 60)) + ':' + remainingTime % 60;

    document.getElementById("TrackPos").childNodes[0].data = currentFormattedTime;
    document.getElementById("SecondsRemain").childNodes[0].data = remainingFormattedTime;
}

function padTime(time) {
    if(time < 10) {
        return '0' + time;
    }
    return time;
}
which works, however, when the seconds for time remaining is less than ten, it still displays as ##:#. Everything else works though.

Bobbin Threadbear
May 6, 2007

You need to pad the "remainingTime % 60" expression.

Bobbin Threadbear fucked around with this message at 07:34 on Feb 5, 2013

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Bobbin Threadbear posted:

code:
function padTime(time) {
    if(time < 10) {
        return '0' + time;
    }
    return time;
}

I call the same function pad10 and it's probably one of my most copy-pasted pieces of code.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



code:
function leftPad(thing, withThis, minLen){
   var temp = thing.toString().split('');
   while(temp.length < minLen){
      temp.unshift(withThis);
   }
   return temp.join('');
}
Not perfect, but it works most of the time.

Munkeymon fucked around with this message at 16:26 on Feb 5, 2013

Bobbin Threadbear
May 6, 2007

Wheany posted:

I call the same function pad10 and it's probably one of my most copy-pasted pieces of code.

Simplicity is beauty

Tei
Feb 19, 2011

What is the best way to make basic calculations with money in JavaScript, without ridiculous stuff like losing cents? It seems the moment you use lots of discounts and tax calculations, all the possible stuff that can go wrong with float values go wrong.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Tei posted:

What is the best way to make basic calculations with money in JavaScript, without ridiculous stuff like losing cents? It seems the moment you use lots of discounts and tax calculations, all the possible stuff that can go wrong with float values go wrong.

Do everything in regular integers that represent 1/100 of a cent. Use formatting functions to display things to that they look right.

Tei
Feb 19, 2011

Munkeymon posted:

Do everything in regular integers that represent 1/100 of a cent. Use formatting functions to display things to that they look right.

Thanks! thats simple enough, It looks foolproff.

NotWearingPants
Jan 3, 2006

by Nyc_Tattoo
Nap Ghost

My Rhythmic Crotch posted:

I've actually been evaluating Ext JS at the same time as Kendo. It does seem very mature, but I'm basically a one-man-band developing the entire site, and the learning curve for Ext JS is really putting me off. Perhaps I will just have to stick with it.

I use ExtJS and I absolutely love it. I hope someone eventually makes a Sencha megathread. I haven't had the time to do it right.

The learning curve is indeed a bit steep, but that often can be attributed to people not knowing CSS or how to use browser web developer/debugger tools. Often when people try to learn ExtJS they are actually trying to learn multiple things at one time, and they tend to bundle all their difficulties into one "ExtJS is really hard" package.

Optimus Prime Ribs
Jul 25, 2007

Munkeymon posted:

Do everything in regular integers that represent 1/100 of a cent. Use formatting functions to display things to that they look right.

Couldn't you still end up with erroneous behaviour since all numbers in JavaScript are floats?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Optimus Prime Ribs posted:

Couldn't you still end up with erroneous behaviour since all numbers in JavaScript are floats?

Only if you use a decimal somewhere in your calculations. Or run into the upper limit, but that's 2^1023, which is a hell of a lot of money even when dealing with 100ths of a cent. I'm guessing people aren't going to be calculating the hypothetical national debt of the United States in 2000 years in whatever page he's writing.

Munkeymon fucked around with this message at 22:13 on Feb 7, 2013

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
I think the relevant limit would be 2^53 / 10^4 or about $900 billion, and any operation other than addition or subtraction is going to introduce trailing digits that could still affect the result if the calculations are long enough.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Gazpacho posted:

I think the relevant limit would be 2^53 / 10^4 or about $900 billion, and any operation other than addition or subtraction is going to introduce trailing digits that could still affect the result if the calculations are long enough.

You're partially right - I misread the limits, but it's not a matter of introducing trailing digits and any operation will be wrong:

code:
Math.pow(2,53) // 9007199254740992
Math.pow(2,53) + 1 // 9007199254740992
(Math.pow(2,53) + 1) % 10 // 2
Math.pow(2,53) % 10 === (Math.pow(2,53) + 1) % 10 // true

Optimus Prime Ribs
Jul 25, 2007

Ah, okay.
So floating points won't give inaccurate values if you treat them as integers? That only happens when decimals are used (e.g. 0.3*3)?

Hughlander
May 11, 2005

As Gazpacho mentioned above, an integer value that falls within 2^53 can be represented exactly as a double. This is due to how the IEEE specification works, there's 53bits for a base, and then 10 for exponent, and one for sign. So with an exponent of 1, you can have exact values for -2^53 - 2^53.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
I don't see how moving from cents to hundredths of cents improves anything at all and if it does I'd wonder if you are carrying out the calculations in the wrong order. It might be useful to talk with someone who has an accounting background about how these particular calculations should be done from their point of view.

Gazpacho fucked around with this message at 21:40 on Feb 8, 2013

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Gazpacho posted:

I don't see how moving from cents to hundredths of cents improves anything at all and if it does I'd wonder if you are carrying out the calculations in the wrong order. It might be useful to talk with someone who has an accounting background about how these particular calculations should be done from their point of view.

It's because using integers to represent hundredths of a cent eliminates floating point representation problems (at reasonable scales) while retaining a good bit of precision (as long as you're careful not to divide by anything - that'll probably cause non-integers to creep into the calculations).

Or you could use a library. Whatever.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Munkeymon posted:

Or you could use a library. Whatever.

If accuracy is really important, you probably should. "Use a library" is almost always better than rolling your own

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde

Munkeymon posted:

It's because using integers to represent hundredths of a cent eliminates floating point representation problems (at reasonable scales) while retaining a good bit of precision (as long as you're careful not to divide by anything
I suppose it might appear to if you are, say, applying tax to each item in a bill rather than to the total of items, to give one example of why it might be useful to talk to an accountant about the recommended way of doing the calculation.

e: Point is, don't rely on a library or a scaling factor to magically save you from lossy calculations if you can avoid them in the first place.

Gazpacho fucked around with this message at 03:03 on Feb 9, 2013

Tei
Feb 19, 2011

Wheany posted:

If accuracy is really important, you probably should. "Use a library" is almost always better than rolling your own

What library?, I have seen a Bignumber library for javascript, so I could use numbers like 9999999999.99999999999999999999 If I need to. Are people suggesting this option?

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Tei posted:

What library?, I have seen a Bignumber library for javascript, so I could use numbers like 9999999999.99999999999999999999 If I need to. Are people suggesting this option?

Well, is accuracy important? Do you have a huge number of values to calculate? (a dozen items costing $7.99 each with a 5% discount, 13% VAT and a $5 coupon isn't going to be a problem)

Does the Javascript code have a final say in what the value is going to be, or is it just used for a preview e.g. refreshing the number of items in a showpping cart?

Is real money involved?

Tei
Feb 19, 2011

I have a program in mind. But I asked this because I know what is the opinion of people, or to know if theres a better way to do it. There must be a better way!.

Wheany posted:

Well, is accuracy important?

Well.. yes.. is money. People don't like wen money is lost.

quote:

Do you have a huge number of values to calculate? (a dozen items costing $7.99 each with a 5% discount, 13% VAT and a $5 coupon isn't going to be a problem)

Not a big number of units, but many calculations: discounts, vat, coupons and other weird stuff.

quote:

Does the Javascript code have a final say in what the value is going to be, or is it just used for a preview e.g. refreshing the number of items in a showpping cart?

Has the final say. Lets say... a POS Terminal.

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Tei posted:

Has the final say. Lets say... a POS Terminal.

Classic Green or Amiga Amber?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply