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.
 
  • Locked thread
Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

Notorious QIG posted:

guys last week i had to convert from degrees to radians by hand, without using a built-in library function

truly i have suffered the most

this sounds EXTREMELY BAD!!

Adbot
ADBOT LOVES YOU

30 TO 50 FERAL HOG
Mar 2, 2005



BattleMaster posted:

the appeal of what you want is limited enough that several people can't think of a reason why it needs to be standard

if it really does come up that much for you suck it up and write a function that does it and it would have taken you less time than you needed to bitch about it on the internet

listen bud if i stopped bitching about dumb poo poo on the internet i would probably have nothing left to post about

BattleMaster
Aug 14, 2000

fair point

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
actually, imagining that some terrible dragon lurks within the conversion to percentages is the behavior of a good programmer, not a terrible one.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
i mean, there's floats in there, it's potentially some kind of weird string and not really a number at all. should you be persisting things as a percentage or as the numerator/denominator? also casting to an int seems incorrect to me in most cases.

there's plenty of potential thorniness there.

quiggy
Aug 7, 2010

[in Russian] Oof.


Captain Foo posted:

this sounds EXTREMELY BAD!!

*writes M_PI*

*spends several years in therapy*

FamDav
Mar 29, 2008

Asymmetrikon posted:

no, it's just a really lovely version of the option monad

nah, option monad requires you to either attempt evaluations within a context or handle the empty case. this is like really wanting a lang where null swallows all method calls. null object is garbage.

HoboMan
Nov 4, 2010

is there some sane reason for why all this javascript i'm looking at is couching all page changes in try-catch blocks (note: the catch part of the block is empty for all of them)?

JawnV6
Jul 4, 2004

So hot ...

MALE SHOEGAZE posted:

i mean, there's floats in there, it's potentially some kind of weird string and not really a number at all. should you be persisting things as a percentage or as the numerator/denominator? also casting to an int seems incorrect to me in most cases.

there's plenty of potential thorniness there.

that's why the correct answer, linked last page and completely ignored, handles at least the cultural issues around it

HoboMan
Nov 4, 2010

FamDav posted:

nah, option monad requires you to either attempt evaluations within a context or handle the empty case. this is like really wanting a lang where null swallows all method calls. null object is garbage.

but you stop getting all those pesky nullpointerexceptions, the bane of a java programmer's existence

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
https://www.youtube.com/watch?v=bLHL75H_VEM

Soricidus
Oct 21, 2010
freedom-hating statist shill

HoboMan posted:

is there some sane reason for why all this javascript i'm looking at is couching all page changes in try-catch blocks (note: the catch part of the block is empty for all of them)?

the most likely explanation, is that it was written by a terrible programmer

30 TO 50 FERAL HOG
Mar 2, 2005



JawnV6 posted:

that's why the correct answer, linked last page and completely ignored, handles at least the cultural issues around it

the string format is A Good Solution for presenting a percentage to the user, but for this case i need an int for comparison purposes so i guess im just gonna do a lot of bad and ugly casting

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

BiohazrD posted:

the string format is A Good Solution for presenting a percentage to the user, but for this case i need an int for comparison purposes so i guess im just gonna do a lot of bad and ugly casting

what

Shaggar
Apr 26, 2006

BiohazrD posted:

the string format is A Good Solution for presenting a percentage to the user, but for this case i need an int for comparison purposes so i guess im just gonna do a lot of bad and ugly casting

tfw you know someone is doing something wrong and you want to know why, but u know asking will just make more work for u.

30 TO 50 FERAL HOG
Mar 2, 2005



the user gets asked for a percentage, so they put in an int. lets say 50. its not like i can ask them to convert it to decimal before they enter it

so i convert the user input into a decimal (.5) and compare that to my calculated percentage (<= .5 is a failure state, > .5 is aokay)

im not actually going all the way to an int because thats dumb but the situation made me think "huh why isnt there a function to do this so i dont have to look at nasty casts"

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

BiohazrD posted:

the user gets asked for a percentage, so they put in an int. lets say 50. its not like i can ask them to convert it to decimal before they enter it

so i convert the user input into a decimal (.5) and compare that to my calculated percentage (<= .5 is a failure state, > .5 is aokay)

computer, calculate 50% of 100. but if you return exactly 50, throw an error.

30 TO 50 FERAL HOG
Mar 2, 2005



anthonypants posted:

computer, calculate 50% of 100. but if you return exactly 50, throw an error.

what the gently caress are you talking about

the calculated percentage is an outside system that is being monitored, that outside system can at any time report the number of discrete data points that it has (Y), and the number of those data points that are determined to be within an acceptable range (X)

X/Y = percent

if that calculated value falls below the user specified threshold (in this example 50% or .5) then the system should be considered to be in a failure state

Bloody
Mar 3, 2013

so uhh why can't you just do input <= 50

quiggy
Aug 7, 2010

[in Russian] Oof.


are you complaining that you need to cast the user input string to a number? because that's, like, p common. not sure how it works in c# but in c/c++ you can really easily just scanf or atoi it

Soricidus
Oct 21, 2010
freedom-hating statist shill

BiohazrD posted:

X/Y = percent

quoting for shame

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
how do i calculate percentage in jquery?

Shaggar
Apr 26, 2006

BiohazrD posted:

the user gets asked for a percentage, so they put in an int. lets say 50. its not like i can ask them to convert it to decimal before they enter it

so i convert the user input into a decimal (.5) and compare that to my calculated percentage (<= .5 is a failure state, > .5 is aokay)

im not actually going all the way to an int because thats dumb but the situation made me think "huh why isnt there a function to do this so i dont have to look at nasty casts"

theres probably a jquery that masks the percentage value as int for the user w/ a decimal submission value

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Wheany posted:

how do i calculate percentage in jquery?

code:
var percentage = require("percentage")
percentage(0.42)  // "42%" 
https://github.com/EvanHahn/percentage.js/blob/master/percentage.js

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
no joke suddenly I got a realization about why people like javascript

by seeing BioHazrD complaining here about converting user input

30 TO 50 FERAL HOG
Mar 2, 2005



Lmao this has nothing to do with user input

If you want an integer representation of a percentage you have to do a shitload of casts. That's fine because integer division is not decimal division. But when your own common library (such as in backgroundworker) wants a value in this form maybe provide an easy way to do it so you don't get horrible looking code with 20 casts in one line

30 TO 50 FERAL HOG
Mar 2, 2005



Like the math library is right there and it does tons of poo poo. Throw a percentage function in there! gently caress

JawnV6
Jul 4, 2004

So hot ...

BiohazrD posted:

you have to do a shitload of casts

:allears:

Shaggar
Apr 26, 2006

BiohazrD posted:


If you want an integer representation of a percentage

you don't want this

30 TO 50 FERAL HOG
Mar 2, 2005



Shaggar posted:

you don't want this

Maybe tell microsoft that

https://msdn.microsoft.com/en-us/library/ka89zff4(v=vs.110).aspx

quiggy
Aug 7, 2010

[in Russian] Oof.


BiohazrD posted:

Like the math library is right there and it does tons of poo poo. Throw a percentage function in there! gently caress

i dont know c# very well so here's a c++ version for you

code:
int percentage(double percent) {
  return static_cast<int>(100.0 * percent);
}
hope that helps :tipshat:

Shaggar
Apr 26, 2006

this is because the progress bars in some cases use int values for max and current. its not for percentage, but you could certainly just show current as "{0}%"

raminasi
Jan 25, 2005

a last drink with no ice

that is a legitimate api gripe but BackgroundWorkers are old news, use tasks and IProgress<T>

raminasi
Jan 25, 2005

a last drink with no ice

Shaggar posted:

this is because the progress bars in some cases use int values for max and current. its not for percentage, but you could certainly just show current as "{0}%"

the linked doc page literally says "The percentage, from 0 to 100, of the background operation that is complete."

Shaggar
Apr 26, 2006
yeah but its intention is for use in progress bars. not a litterral percentage display, tho you could do that too.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Shaggar posted:

this is because the progress bars in some cases use int values for max and current. its not for percentage, but you could certainly just show current as "{0}%"

nah it explicitly says it's a percentage and doesn't provide any obvious way to specify a max that isn't 100

microsoft made a bad api, it happens sometimes

Shaggar
Apr 26, 2006
its percentage complete but its intended for user display in progress bars where the progress bars take a current and max int value for display. that's why the api is done that way.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
c enterprise programming s: getting Conway's law'd so hard

Soricidus
Oct 21, 2010
freedom-hating statist shill
but that's a flawed api. if the progress bars take a current and max integer then the api should work with current and max integers, not hardcode the max to be 100.

Adbot
ADBOT LOVES YOU

cinci zoo sniper
Mar 15, 2013




im looking at the pile of poo poo ive cobbled up since the last spring and its slowly creeping into my mind that coder's salary is literally is a function of usable their poo poo is

  • Locked thread