FAQ Database Discussion Community

## Calculate percentage Javascript

javascript,html,percentage,argument-passing
I have a question about javascript logic what I use to get percent of two inputs from my text fields. Here is my code: var pPos = \$('#pointspossible').val(); var pEarned = \$('#pointsgiven').val(); var perc = ((pEarned/pPos) * 100).toFixed(3); \$('#pointsperc').val(perc); For some reason if my inputs are 600 and 200, my...

## Chance of a conditional occurring in Swift: Xcode

xcode,swift,if-statement,conditional,percentage
I am quite new to Xcode and swift so sorry if this is a bad description. Is there a way that there is a chance of your conditional occurring so instead of it happening 100% of the time when the conditions are met, it only happens 50% of the time...

## R Program Vector, record Column Percent

r,vector,percentage
This is my vector head(sep) I must find percent of all SEP 11 in each row. For instance, in first row, percent of SEP 11 is 100 * ((63 + 124)/ (63 + 124 + 0 + 0)) And would like this stored in newly created 8th column Thanks dput...

## How should a certain percentage of evenly-distributed elements of a Python list be extracted?

python,list,distribution,percentage
I have a list of data points. For the full run of my program, I'll use all of the data points, but for testing of the code, I want to use only a small percentage of them in order that the program run in a short time. I do not...

## Calculating a percentage in SQL

sql,sql-server,count,division,percentage
I'm trying to calculate a percentage in SQL. I want to find out to get the percentage of output start with 'RT @' CREATE TABLE temp ([tweet] varchar(130)) ; INSERT INTO temp ([tweet]) VALUES ('WillyWonka'), ('Barbara'), ('JoanOfArcJoanArcadia'), ('LisaDLisa Diddle'), ('LisaDSkip Padington'), ('WillyNillySiil Stoinson'), ('RT @Barbara'), ('JoanOfArcJoanArcadia'), ('LisaDLisa Diddle'), ('RT @LisaDSkip...

## PHP subtract a percentage result

numbers,percentage,subtract
\$temp_price_1 = round(\$price * ((100-\$sale_percentage) / 100), 2); \$price = \$temp_price_1; im using this code to subtract a percentage from a number, for this example my starting number for \$price is 24.99 and the \$sale_percentage is 50.0 this result is the \$temp_price_1 being 12.5 which is correct, however i need...

## Is there an easy way to get the percentage of successful reads of last x minutes?

c,arrays,algorithm,percentage
I have a setup with a Beaglebone Black which communicates over I²C with his slaves every second and reads data from them. Sometimes the I²C readout fails though, and I want to get statistics about these fails. I would like to implement an algorithm which displays the percentage of successful...

## Unix head/tail a percentage of lines to an output file

I'm using unix to read through an excel file, sort by one column, and then I want a percentage (lets say the top 10%) of the sorted lines exported to a new .xls file. I have the code below which works fine but I need to do a wc -l...

## Padding top as percentage of width not working

Here is my example code: body { margin: 0; padding: 0; border: 0; background: #444; } #container { width: 25px; margin: auto; margin-top: 2px; padding-top: 1%; border-bottom: 3px solid #58e; background: #fff; } <div id="#container">text</div> When I run it in chrome and inspect element the computed style of the div,...

## How % works in Python [duplicate]

python,percentage
This question already has an answer here: How does % work in Python? 15 answers I have searched but it looks like this is almost too basic to have been posted prior to this. I am starting to learn Python and I have been given an example to write....

## Calculate Uncertainty of Percentage in R and plot in scatter plot

r,plot,percentage,scatter-plot,uncertainty
I have this data set where I calculate the percentage of fall given an age. Total Members is the whole date by a given age, and members fallen is the amount of falls within the total member. age status membersFallen totalMember percentage 37 1 208 14824 1.4 38 1 443...

## count cells quantity with a special contained word and calculate the percentage

string,excel,count,percentage
How can I count cells quantity with a special contained word and calculate the percentage in excel? For example I have a survey database about a product. the feedbacks are "Good, Not Bad, Bad". I want to count the quantity of each type of feedbacks and finally calculate the percentages...

## How to display percentage with one decimal and manage culture with string.Format in C#?

c#,.net,format,percentage,string.format
I would like to display a percentage and manage the culture. Like this : https://msdn.microsoft.com/fr-fr/library/system.globalization.numberformatinfo.percentnegativepattern%28v=vs.110%29.aspx I do that : double percentage = 0.239; NumberFormatInfo nfi = CultureInfo.CurrentCulture.NumberFormat; string percentageValue = string.Format(nfi, "{0:P1}", percentage); It works (for example result can be "%23,9" or "23,9 %") But I don't want to display...

## Unexpected result when calculating a percentage - even when factoring in integer division rules

c,percentage,integer-overflow,integer-division
I am trying to express a battery voltage as a percentage. My battery level is a (global) uint16 in mV. I have a 16-bit CPU. Here is my code: static uint8 convertBattery(void){ uint16 const fullBattery = 3000; /* 3V = 3000mV */ uint8 charge; charge = ((battery*100)/fullBattery); return charge; }...

## Making a customized forest plot of two groups using R

r,graph,plot,categories,percentage
I would really like to make a plot like this one using R. I've experimented with the forest() command from the metafor package but can't seem to create anything comparable. I also have two groups, multiple categorical variables, and percentages - basically, exactly the same kind of data shown in...

## Double square in CSS

html,css,percentage
I try to create 19 squares, the first double size. Regular square: width: 9.09%; padding: 2.27% 0;. So, I used for the first width: 18.18%; padding: 4.54% 0;. But doesn't have double height than the others. Here's a JSFiddle. Which would be the right percentage for padding? And why is...

## Convert CSS positioning from percentage to pixels

javascript,jquery,percentage,pixels
I have a headline vertically centered, like so: h1{ position: absolute; height: 30px; top: 50%; margin-top: -15px; } Now I want to use jQuery to convert the current position to pixels. But if I try this: \$('h1').css('top', \$('h1').offset().top.toString() + "px") The headline moves up a little. What am I missing...

## calculate % change in javascript

javascript,math,percentage
var current = 12000; var june = 14600; var may = 11200; I want percent change with respect to 'current' month parameter. The output should be in percent and it can add or subtract w.r.t. the current month. How to do this?...

## R format number syntax

r,percentage
I'm trying to display some numbers as percentages. data <- read.csv( "http://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data", header = FALSE, na.strings = "?", strip.white = TRUE ) colnames(data) <- c("age", "workclass", "fnlwgt", "education", "education-num", "marital-status", "occupation", "relationship", "race", "sex", "capital-gain", "capital-loss", "hours-per-week", "native-country", "prediction") colSums(is.na(data))/nrow(data)*100 The last command there outputs age workclass fnlwgt education education-num...

## % of total calculation without subquery in Postgres

sql,postgresql,aggregate-functions,percentage
I'm trying to create a "Percentage of Total" column and currently using a subquery with no issues: SELECT ID, COUNT(*), COUNT(*) / (SELECT COUNT(*) FROM DATA) AS % OF TOTAL FROM DATA GROUP BY ID; | ID | COUNT | % OF TOTAL | | 1 | 100 | 0.10...

## Django translations block not translated [duplicate]

django,templates,translation,percentage,django-i18n
This question already has an answer here: Handling percent-sign (%) in Django blocktrans tags 3 answers I have a Django 1.6 template with the following content (base language is german, the translation is in english): {% trans "My App" as appname %} {% blocktrans with appname=appname %}Garantie: '{{ appname...

## Using percentage function with accumarray

arrays,matlab,percentage,accumarray
I have two arrays: OTPCORorder = [61,62,62,62,62,62,62,62,62,62,62,62,65,65,...] AprefCOR = [1,3,1,1,1,1,1,1,1,1,2,3,3,2,...] for each element in OTPCORorder there is a corresponding element in AprefCOR. I want to know the percent of the number 1 for each set of unique OTPCORorder as follows: OTPCORorder1 = [61,62,65,...] AprefCOR1 = [1,0.72,0,...] I already have this:...

## How to apply scales::percent or scales::percent_format() to prop.table in R to format numbers as percentages

r,formatting,plyr,percentage,crosstab
Consider the following example: tab <- table(mtcars\$vs, mtcars\$cyl, dnn = c("vs", "cylinder")) prop.table(tab) # cylinder # vs 4 6 8 # 0 0.03125 0.09375 0.43750 # 1 0.31250 0.12500 0.00000 round(prop.table(tab)*100, 1) # cylinder # vs 4 6 8 # 0 3.1 9.4 43.8 # 1 31.2 12.5 0.0 Desired...

## How to set margins as percentage of parent layout's size?

android,percentage,margins
I wanna set the margins as percentage. like this.. ViewGroup.MarginLayoutParams margin = new ViewGroup.MarginLayoutParams(iv_Dot.getLayoutParams()); margin.setMargins(30%, 20%, 0, 0); But, setMargins method is to support only int type. How can i set margins as percentage?. If, I get parent size. and then, calculate percentage. I can solve this problem. Is there...

## CSS percentage width not working

I've been trying to edit the CSS for my website's navbar in order to transform it from having fixed width and height values into percentage values (in order for it to become responsive and work better with different screen sizes). However, when I converted the values, the individual divs didn't...

## How do I calculate the percentage of one column to another?

sql,sql-server,percentage
I have a query: SELECT CAST(SUBMITDATE as date) as 'Date' ,COUNT(*) as [Tickets Submitted] ,SUM(CASE WHEN STATUS = 'Closed' THEN 1 ELSE 0 END) as [Tickets Closed] FROM Table1 WHERE SUBMITDATE >= '2015-05-29' AND SUBMITDATE < '2015-06-03' GROUP BY CAST(SUBMITDATE as date) which produces the following result: Date Tickets Submitted...

## percentage width in css not working

html,css,width,viewport,percentage
I was using a way to define my width property in css with the viewport measurement, css code: #content { position: absolute; background-color: white; width: 100vw; top: 115px; bottom: 30px; display: table; z-index: 0; } When I changed the width from width: 100vw; to width: 100%; my code ain't working...

## How can I find the ratio between two file sizes as a percentage in Python?

python,math,percentage,filesize,ratio
I've written a short Python script to find the original and minified sizes of a script, by comparing file sizes, and to find the difference and compression ratio. The script itself follows: #! /usr/bin/python import os import sys file1 = sys.argv file2 = sys.argv file1Size = os.stat(file1).st_size file2Size = os.stat(file2).st_size...

## Calculating real value

php,statistics,percentage
I'm trying to run sales report to find which products sold the most, but sold/available doesn't really give a real measure of of performance because for example: Product 1: 6 sold of 8 = 75% Product 2: 232 sold of 500 = 46.4% .. so although Product 2 is clearly...

## From multiple matricies, calculate percentage of a value from each matrix and store them into a new vector

r,function,matrix,percentage,na
I searched through stackoverflow and have failed to find a solution to my specific problem. Here, I want to calculate the percentage of an element from multiple matrices with NA values, and store the calculations into a new vector - specifically, each matrix contains 1s, 0s, and NA values. This...

## Add on a percentage to a variable value in Smarty 2 template

php,smarty,percentage,php-5.4,smarty2
I have assigned a variable in my Smarty 2 template. {assign var="real_count" value="{\$store_summary|@count}"} {\$real_count = settype (\$real_count, 'integer')} My goal is to add on 65% to the value of \$real_count. With the data i'm working with I have a \$real_count of 3, so the calculated value should be 4.95 (3...

## How to draw a ggplot2 with facet_wrap, showing percentages from each group, not overall percentages?

r,ggplot2,percentage,facet
I'd like to draw a ggplot with facet_wrap, which doesn't show the actual table percent, but the percent of the given answer in each group. I have to do this, because I want to show, which answer is most selected and most important for each group. The groups don't have...

php,printf,percentage
Here is my code: <?php printf( __( '%.0f' ), \$mini_deck->rating_per.'%' ); ?> My problem is that the "rating_per" percentage sign (%) isn't showing after the percentage number on my website. What's wrong in my code?...

## Calculate percentage for single record in SQLITE

android,sqlite,aggregate-functions,percentage
I have Register table and in this I have following fields like: r_id , f_name , l_name , isactive , pkg pkg field can have values of 1,2,3,4. I want to find out percentage of how many user has pkg value 1 and 2 and 3 and 4. I used...

## How to normalize percentages in python

python,math,numpy,dictionary,percentage
I have a list of dictionaries in python signifying country code and hits percentages for different servers. [{'country': 'BR', 'values': {'Server1': [100.0, 100.0]}}, {'country': 'IE', 'values': {'Server1': [61.7868], 'Server2': [38.2132]}}, {'country': 'US', 'values': {'Server1': [82.19], 'Server2': [100.0]}}] I would like to convert it to a single value keeping the percentages...

## Format point value in hightcharts

javascript,jquery,graphics,highcharts,percentage
I have a graph with 2 line series. Points in each series are percent but I get them from the database in this format : 0.24 for 24% , 0.02 for 2% ... Is there any method for multiply the value by 100 directly in my graph options ? I...

## How to add number to current CSS width with jQuery

jquery,html,css,percentage
I'm working on a meter that goes up or down depending on decisions you make. I'm doing this by changing the width percentage of the CSS with jQuery. Currently I can set it to an arbitrary percent, but I want to add or subtract a percentage from the current value....

## How can I assign a class to a number_to_percentage?

ruby-on-rails,ruby,class,ruby-on-rails-4,percentage
I have the following code: <%= number_to_percentage(a.number, precision: 1) %> How can I give that element a class or id? <%= number_to_percentage(a.number, precision: 1), class: "number" %> returns an error and <%= number_to_percentage(a.number, precision: 1, class: "number") %> doesn't do anything at all. I also don't want to wrap it...

## Same Calculation, different result?

java,math,percentage
My goal is to calculate how many percent counter out of cap is. Now I ran over a problem, I can't find the difference between the two formulas below, as far as my mathematical understanding tells me, it's exactly the same calculation. But only the first one works, brackets make...

## How to fix DIV height when resizing width? Mobile/Table/PC browser compatible

css,resize,height,width,percentage
I have a trouble about % width and height: I would like to give every sizes in percentages (mobile, tablet, pc browser, etc. compatibility) but when I resize the browser WIDTH that causes the HEIGHT to be resized too FOR ALL ELEMENTS. How to stop height modifying when height isn't...

## Select organizations that their income represent around 60% of the total income SQL Server2008

sql-server,sum,data-warehouse,percentage
In advance, I apologize for imperfect English In this data warehouse, we have organization which composed of multiple Organizations, I have [FactFinance] table which has information about the income of each organization. I have the following query in data warehouse which select the (Organization Name) from the [organization dimension table]...

## Format number as percent in MS SQL Server

sql-server,tsql,percentage
I am trying to simply format a number as a percent with two decimal places. If it is 37 divided by 38 (aka .973684210526315789), I would like it to show 97.36 % in the SQL output. I know it is recommended to do formatting in the Application, however this is...

## Trouble getting percentages in C++

c++,percentage
C++ beginner here. I'm trying to replicate this output and I'm almost there but I'm having trouble with the last part (the quiz percentage). Example output: Welcome to our math quiz program! Please enter the answers to the following questions: 5! = 5 (2^(2^(2^2))) = 65536 3 * (4 +...