decimal

Decimal group seperator for the fractional part

五迷三道 提交于 2019-12-02 10:38:41
I wonder what would be the best way to format numbers so that the NumberGroupSeparator would work not only on the integer part to the left of the comma, but also on the fractional part, on the right of the comma. Math.PI.ToString("###,###,##0.0##,###,###,###") // As documented .. // ..this doesn't work 3.14159265358979 // result 3.141,592,653,589,79 // desired result As documented on MSDN the NumberGroupSeparator works only to the left of the comma. I wonder why?? A little clunky, and it won't work for scientific numbers but here is a try: class Program { static void Main(string[] args) { var

Fractions instead of decimals

醉酒当歌 提交于 2019-12-02 10:04:41
So, I am Writing this little program in c++, it's made to compute various values with lines (sorry i am french, i don't know how to say it in English, but they are the lines with equation types Y = kx + t). And I want my program to output fractions instead of decimals (2/3 instead of 0.666666666...). Can anyone tell me how ? I read online that there are some libraries for that purpose, can anyone help me on how to use them and/or how to implement them in my code ? Thanks :) #include "pch.h" #include <iostream> #include <string> std::string mainAnswer; bool endVar = false; void

Why are the decimals not adding up correctly?

只愿长相守 提交于 2019-12-02 09:47:25
I'm working on a program where you can choose up to 3 things you want to divvy points amongst. Say for example that an action gains you 4 points, and those 4 points are divvied amongst the 3 things you selected. In this case, those 3 things each get 1.33333... points. In my database, they are stored as 1.33. However when I bring them out, it tallies up to 3.99. Understandable. But how can I avoid this without giving one of the things 1.34 points? Store the full float/double in your database rather than truncating to 2 decimal places. The time to trunc is when displaying the value to the user -

How to convert Time to Decimal in SQL with an integer

点点圈 提交于 2019-12-02 09:44:30
I am having a couple of issues converting time to decimal... Essentially I have used a DATEDIFF to identify the hours and minutes between two dates and times. This produces a result of 5.45, however I would like to get the result as 5.75. select RTRIM(DATEDIFF(second, startdate, enddate)/3600)+'.' + RIGHT('0'+RTRIM((DATEDIFF(second, startdate, enddate) % 3600)/60),2) from time I have tried a few things but I believe the issue is that this is not an integer and that's why i cant convert the minutes. Get the time difference in minutes, and divide by 60, this will place hours before the decimal

Calculate large decimals (more than 15 digits) in Javascript

老子叫甜甜 提交于 2019-12-02 09:41:22
As we know, Javascript has some issues (or features) with calculating decimal numbers. For example: console.log(0.1 + 0.2) // 0.30000000000000004 And we know that we can avoid it using different libraries (for example I use bignumber.js ), and now we have what expected: console.log(Number(new BigNumber(0.1).plus(0.2))); // 0.3 <script src="https://cdnjs.cloudflare.com/ajax/libs/bignumber.js/6.0.0/bignumber.min.js"></script> BUT Bignumber.js has limitations: It accepts a value of type number (up to 15 significant digits only), string or BigNumber object. We can pass a string (it's possible),

Converting hex to dec C++

℡╲_俬逩灬. 提交于 2019-12-02 09:30:48
Convert to hex: cout << hex << int(x) << endl; How to convert conversely, from hex to dec? Enter hex number simple: cin >> hex >> x; You can use the std::dec IO manipulator : std::cout << std::dec << int(x) << endl; Note that this is only necessary if you have previously used std::hex or other means to manipulate the base of std::cout . Otherwise you need take no action: the default for an int is decimal. Don't use the std::hex manipulator? std::cout << int(x) << std::endl; 来源: https://stackoverflow.com/questions/17781115/converting-hex-to-dec-c

ios - dynamically create and display unicode strings

谁说胖子不能爱 提交于 2019-12-02 09:23:39
I have a UILabel in which I want to display a Unicode character. The following works: label.text = @"\U000025A0"; Now I want to dynamically generate the Unicode character from a decimal number as follows: label.text = NSString stringWithFormat:@"\U%08x",9632]; Xcode compiler fails with the following error: \U used with no following hex digits Is there a way to convert the decimal number 9632 to Unicode and then display it in a UILabel ? I had a same issue to display entypo Font special character, so I implemented my own EntypoStringCreator class (with some help from SO). Here are the method

Precision of decimals in Python

霸气de小男生 提交于 2019-12-02 09:21:07
I don't mean precision as in how many numbers are displayed after the decimal. I mean precision as in the decimal I am trying to use in this pictograph function keeps coming up one tenth shy of what it should be. I have tried using multiple different strategies including importing the decimal module. Here is the function I am trying to use. values = [('tens', 10), ('fives', 5), ('ones', 1), ('tenths', 0.1)] def get_digits(num): num = int(num * 10) num = float(num) / 10 output_dict = {} for place, value in values: output_dict[place] = int(num // value) num = num % value return output_dict using

PHP - Find the number of zeros in a decimal number

两盒软妹~` 提交于 2019-12-02 09:17:32
问题 Let's say we have 0.00045. I want to find a way to count the number of "significant" zeros after the decimal point (3 in this case). I've been trying to implement strpos or substr , but I'm getting stuck. Other exs.... 3.006405: Should return "2" 0.0000062: Should return "5" 9.0100000008: Should return "1" Any ideas? 回答1: strspn($num, "0", strpos($num, ".")+1) strspn finds the length of a sequence of zeroes. strpos finds the position of the decimal point, and we start from 1 position past

decimal formatting without rounding .net

拈花ヽ惹草 提交于 2019-12-02 09:12:48
问题 Yesterday I asked this general question about decimals and their internal precisions. Here is a specific question about the scenario I'm trying to address. I have column in SqlServer that is typed - decimal(18,6). When I fetch these values, the .net decimals that are created match the precision in the database. They look like this: 1.100000 0.960000 0.939000 0.844400 0.912340 I need to present (ToString) these values according to these rules: Non-zeroes are always shown. Trailing zeroes on or