decimal

atoi and leading 0's for decimal numbers

泄露秘密 提交于 2020-01-07 04:19:13
问题 When using atoi in C I am trying to convert a char array of numbers to an int . I have leading 0 's on my number though and they are not preserved when I print the number out later. char num[] = "00905607"; int number; number = atoi(num); printf("%d", number); The output from this will be 905607 and I would like it to be 00905607 . Any ideas? 回答1: Use strtol instead. It allows you to specify the base. 回答2: You can do padding on your printf() so if you wanted every output to be 8 characters

Remove a decimal place in PHP

我是研究僧i 提交于 2020-01-07 03:51:23
问题 In PHP, I am getting numbers from a database with 3 decimal places. I want to remove the last decimal point. So 2.112 will become 2.11, 23.123 will become 23.12 and 123.267 will become 123.26. Its like doing a floor at a decimal level. 回答1: You can use number_format , you specify the number of decimal places as the second arugment. Example $number = 534.333; echo number_format($number,2) // outputs 534.33 Or use round $number = 549.333; echo round($number, 2) // outputs 534.33 Seems like

Why is Swift Decimal Returning Number from String Containing Letters?

雨燕双飞 提交于 2020-01-07 03:16:26
问题 I am working with Swift's Decimal type, trying to ensure that an user-entered String is a valid Decimal . I have two String values, each including a letter, within my Playground file. One of the values contains a letter at the start, while the other contains a letter at the end. I initialize a Decimal using each value, and only one Decimal initialization fails; the Decimal initialized with the value that contains the letter at the beginning. Why does the Decimal initialized with a value that

Why is Swift Decimal Returning Number from String Containing Letters?

人盡茶涼 提交于 2020-01-07 03:15:31
问题 I am working with Swift's Decimal type, trying to ensure that an user-entered String is a valid Decimal . I have two String values, each including a letter, within my Playground file. One of the values contains a letter at the start, while the other contains a letter at the end. I initialize a Decimal using each value, and only one Decimal initialization fails; the Decimal initialized with the value that contains the letter at the beginning. Why does the Decimal initialized with a value that

Entity framework support for MySql unsigned decimal

孤人 提交于 2020-01-06 14:53:46
问题 Entity framework just ignores unsigned decimal column when doing db-first to generate code, since I can't change the data type of the db column to signed, any solution? 回答1: Do you need to "enforce" non-negative values? Use a TRIGGER . Or, if the values are whole numbers, then use some suitably sized INT UNSIGNED in place of DECIMAL . 来源: https://stackoverflow.com/questions/34566718/entity-framework-support-for-mysql-unsigned-decimal

MySQL out of range value for decimal column

那年仲夏 提交于 2020-01-06 08:09:52
问题 After searching, I found plenty of out of range problems with people not knowing that the first digit, m, in decimal(m,n) is the total amount of digits. However, that is not my problem. For the column in question I have the following: Field | Type | Null | Key | Default | Extra preco | decimal(50,2) unsigned | NO | | 0.00 | The setting decimal(50,2) is way more than I really want or need. I really only want 10 digits total. Its a price, so anything over 100 million is probably ridiculous, so

How to make the value of the decimal only show in numerals?

时光总嘲笑我的痴心妄想 提交于 2020-01-06 06:58:55
问题 Im trying to make my c program run any value that you put in will come out as words for example if I wanted to put in the value 1234.56 it should come out as "One Thousand Two Hundred Thirty Four Dollars ... and 56 Cents" Notice how the cents are only in numerals. So far I have properly written the code that will be able to transfer the numbers to words but I have no clue how to only leave the part for the cents alone. Please help!! Currently for the decimals I get some outrageous number in

Input string was not in a correct format (Decimal to String)

▼魔方 西西 提交于 2020-01-06 05:48:09
问题 am trying to convert a decimal to a string which I have done sucesfully in the past but for some reason its deciding not to work now. I really can't get my head around it, I have set it to decimal in SQL Management Studio and used linq to entites to pass it through but for some bizarre reason unknown to mankind it thinks am asking for a datetime. Code: protected void btnSubmit_Click(object sender, EventArgs e) { try { tblTest t = new tblTest(); t.tDecimal = Convert.ToDecimal(tbxDecimal

How to convert Hexadecimal to Decimal?

落花浮王杯 提交于 2020-01-05 13:06:19
问题 I have different hexadecimal data are coming and stored into an integer type register. When I use fprint I can see the following: 0x3076 0x307c . . . However, I would like to show a Decimal version of above-mention Hex data as follows. 12406 12412 . . . In theory, let's say for the first value you do the following to convert it to decimal. (6* 16^0)+(7 * 16^1)+(0*16^2)+(3*16^3)=6 + 112+ 0 + 12288 = 12406 So IF I have the character-based version of "0x3076" and also, IF I am able to get each

jQuery Flot - Display accurate values

对着背影说爱祢 提交于 2020-01-05 07:36:48
问题 I notice that jQuery Flot is rounding down the results. But I want to show the actual decimal value for the result when you hover over the peaks and valleys in the tooltip. But not the x or y axis labels, but the graph result itself. So instead of "44", I want "44.05". Is there anything I can do to make that work? Everything I'm seeing is just for the axis labels. 回答1: The tool tip should allow you to do this - have a look at this fiddle http://jsfiddle.net/Rnusy/ var previousPoint = null; $(