percentage

Calculating rounded percentage in Shell Script without using “bc”

末鹿安然 提交于 2019-11-30 11:29:21
I'm trying to calculate percentage of certain items in Shell Script. I would like to round off the value, that is, if the result is 59.5, I should expect 60 and not 59. item=30 total=70 percent=$((100*$item/$total)) echo $percent This gives 42. But actually, the result is 42.8 and I would to round it off to 43. "bc" does the trick, is there a way without using "bc" ? I'm not authorized to install any new packages. "dc" and "bc" are not present in my system. It should be purely Shell, cannot use perl or python scripts either Use AWK (no bash-isms): item=30 total=70 percent=$(awk "BEGIN { pc=100

safari rounding down on subpixel calculations

折月煮酒 提交于 2019-11-30 08:43:04
i have a container that takes up 829px on a row, and has a background-image of the same size. i have a div within that container that calculates its width based on the 829px container. on safari, the divs width comes out to be something like 173.8px, but since safari/webkit round down, its truncated and becomes 173px in width. this 829px container has 3 divs inline on the same row. the first div, 1px is lost, the second, 2px is lost, and by the third, 3 pixels are lost, so the third div is shifted left by three pixels. on an ipad, thats 6 pixels lost. i've tried to search for subpixel

video.js size to fit div

北城以北 提交于 2019-11-29 22:21:51
I have a video in a div with a 40% width. In the html, width="100%" height="auto" makes the video disappear. Setting a specific size in pixels won't fit the div . Leaving the html blank leaves the video the wrong size and with black bars on the sides. I've tried the suggestions in most other posts, but can't seem to get it to work. <div id="box"><video id="trialvid" class="video-js vjs-default-skin" controls preload="auto" width="auto" height="auto" poster="images/reelthumbnail.jpg" data-setup='{"example_option":true}'> <source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4

calculating in jtable with %, total

坚强是说给别人听的谎言 提交于 2019-11-29 18:15:32
I am almost at the end of my project and have some problems solving it. I m a chef who wants his own application what is relevant for his own bussines My form is called Recipes and have Qty unitprice, % used. So lets say, you have 1kg apples for 5 euro. At the end of cleaning you just have 800 grams of apples. So i have paid 20 percent more. example Item is always 100%, Qty 5, Unitprice 5, Used% 100% total = 25 Qty 5, Unitprice 5, Used% 70%, Total= 32.5 ( must increase with 30 percent) At the end I would have to calculate the Foodcost. So "Total Cost / Selling price * 100" I m stuck with this

Php, calculate percentage on multiple items

筅森魡賤 提交于 2019-11-29 12:34:00
I have 5 items in total, and I would like to calculate percentage based on [data] filed. The result will be used for pie chart. Array ( [0] => Array ( [label] => Item1 [data] => 849 ) [1] => Array ( [label] => Item2 [data] => 657 ) [2] => Array ( [label] => Item3 [data] => 571 ) [3] => Array ( [label] => Item4 [data] => 538 ) [4] => Array ( [label] => Item5 [data] => 446 ) ) Using: (5/[data])*100 does not produce correct result, and I'm not sure how to perform proper calculations. I think what you want is to sum up all the items to get the total sum first and then determine the percentage of

safari rounding down on subpixel calculations

我的未来我决定 提交于 2019-11-29 12:03:33
问题 i have a container that takes up 829px on a row, and has a background-image of the same size. i have a div within that container that calculates its width based on the 829px container. on safari, the divs width comes out to be something like 173.8px, but since safari/webkit round down, its truncated and becomes 173px in width. this 829px container has 3 divs inline on the same row. the first div, 1px is lost, the second, 2px is lost, and by the third, 3 pixels are lost, so the third div is

background-position percentage not working [duplicate]

别说谁变了你拦得住时间么 提交于 2019-11-29 10:27:47
This question already has an answer here: Using percentage values with background-position on a linear gradient 1 answer Everywhere I read says this should be working fine, but for some reason it's not. This was to fix someone else's issue so fixing it doesn't matter to me, I just want to know why. The problem is on .br .bg-image . I know I'm trying to use calc() but using a simple background-position: 50% doesn't work either. http://jsfiddle.net/uLaa9fnu/2/ html { height: 100%; width: 100%; } body { margin: 0px; height: 100%; width: 100%; overflow: hidden; } .bg-image { height: 600px; width:

Percentage Based Probability

我是研究僧i 提交于 2019-11-29 06:44:37
I have this code snippet: Random rand = new Random(); int chance = rand.Next(1, 101); if (chance <= 25) // probability of 25% { Console.WriteLine("You win"); } else { Console.WriteLine("You lose"); } My question is, does it really calculate a 25% probability for winning here? Is the chance of winning for the player here is really 25%? Edit: I just wrote this: double total = 0; double prob = 0; Random rnd = new Random(); for (int i = 0; i < 100; i++) { double chance = rnd.Next(1, 101); if (chance <= 25) prob++; total++; } Console.WriteLine(prob / total); Console.ReadKey(); And it's highly

Percentage rank of matches using Levenshtein Distance matching

只愿长相守 提交于 2019-11-28 20:20:21
I am trying to match a single search term against a dictionary of possible matches using a Levenshtein distance algorithm. The algorithm returns a distance expressed as number of operations required to convert the search string into the matched string. I want to present the results in ranked percentage list of top "N" (say 10) matches. Since the search string can be longer or shorter than the individual dictionary strings, what would be an appropriate logic for expressing the distance as a percentage, which would qualitatively refelct how close "as a percentage" is each result to the query

How do I calculate the percentage of a number? [closed]

孤者浪人 提交于 2019-11-28 17:24:40
I would like to calculate, in PHP, the percentage of a number. For example: $percentage = 50; $totalWidth = 350; For this example, 50% of 350 = 175 How can I do that? $percentage = 50; $totalWidth = 350; $new_width = ($percentage / 100) * $totalWidth; Divide $percentage by 100 and multiply to $totalWidth . Simple maths. 来源: https://stackoverflow.com/questions/10201027/how-do-i-calculate-the-percentage-of-a-number