decimal

Simple math with decimals in PHP

こ雲淡風輕ζ 提交于 2019-12-31 03:06:10
问题 This is killing me! I've never had so much trouble and I can't figure out what I'm doing wrong here. If I have a number, say 2.32, and I want to do math with it it won't work out. The very simplest example: $income = $commission; //Commission is 2.32, retrieved from XML echo "income: $income<br>"; $income100 = $income*100; echo "income100: $income100<br>"; The result I get is: income: 2.32 income100: 200 How can I use a decimal number accurately with math without it changing it? Thanks so

Eloquent casts decimal as string

元气小坏坏 提交于 2019-12-30 09:30:58
问题 I have a decimal field to represent money in my Eloquent Model and I'm noticing erroneous results when trying to add some number to this field. Upon further inspection, I found that the decimal field is being cast as a string , like "1245114.00" in the tinker console. I checked the table structure and I can verify that the field is indeed decimal(11,3) . This question was asked before but has no answers. Why is this happening? 回答1: You need to define in your model which fields need to be cast

Int to Decimal Conversion - Insert decimal point at specified location

不羁的心 提交于 2019-12-30 07:51:42
问题 I have the following int 7122960 I need to convert it to 71229.60 Any ideas on how to convert the int into a decimal and insert the decimal point in the correct location? 回答1: int i = 7122960; decimal d = (decimal)i / 100; 回答2: Simple math. double result = ((double)number) / 100.0; Although you may want to use decimal rather than double : decimal vs double! - Which one should I use and when? 回答3: Declare it as a decimal which uses the int variable and divide this by 100 int number = 700

How to set a constant decimal value

こ雲淡風輕ζ 提交于 2019-12-30 05:38:17
问题 I'm using C# to set a default value for a decimal value in my config class public class ConfigSection : ConfigurationSection { [ConfigurationProperty("paymentInAdvanceAmount", **DefaultValue = 440m**)] public decimal PaymentInAdvanceAmount { get { return (decimal)base["paymentInAdvanceAmount"]; } set { base["paymentInAdvanceAmount"] = value; } } } but it won't be compiled and throws an error An attribute argument must be a constant expression, typeof expression I found a post says: "It's not

Show decimal of a double only when needed

人走茶凉 提交于 2019-12-30 02:34:56
问题 I got this problem with double (decimals). When a double = 1.234567 Then I use String.format("%.3f", myString); So the result is 1.234 But when my double is 10 The result will be 10,000 I want this to be 10 Is their a way to say that he only needs to show the decimals when it is "usefull"? I saw some posts about this, but that was php or c#, couldn't find something for android/java about this (maybe I don't look good). Hope you guys can help me out with this. Edit, for now I use something

Significant figures in the decimal module

故事扮演 提交于 2019-12-29 08:40:14
问题 So I've decided to try to solve my physics homework by writing some python scripts to solve problems for me. One problem that I'm running into is that significant figures don't always seem to come out properly. For example this handles significant figures properly: from decimal import Decimal >>> Decimal('1.0') + Decimal('2.0') Decimal("3.0") But this doesn't: >>> Decimal('1.00') / Decimal('3.00') Decimal("0.3333333333333333333333333333") So two questions: Am I right that this isn't the

Entity Framework Code First truncating my decimals

不想你离开。 提交于 2019-12-29 07:28:27
问题 I am using Entity Framework 6.x using the Code First approach on an MVC 5 application. In this particular situation my model (among other things) contains two properties named Latitude and Longitude: [Required, Range(-90, +90)] public decimal Latitude { get; set; } [Required, Range(-180, +180)] public decimal Longitude { get; set; } And when I performed the migration I got something like this CreateTable("ResProperty"), c => new { : Latitude = c.Decimal(nullable: false, precision: 10, scale:

Converting string value to hex decimal

风流意气都作罢 提交于 2019-12-29 05:37:11
问题 i am making application in c#. In that implication i have string which contain decimal value as string number="12000"; The Hex equivalent of 12000 is 0x2EE0. Here i want to assign that hex value to integer variable as int temp=0x2EE0. Please help me to convert that number. Thanks in advance. 回答1: An int contains a number, not a representation of the number. 12000 is equivalent to 0x2ee0: int a = 12000; int b = 0x2ee0; a == b You can convert from the string "12000" to an int using int.Parse().

ValueError: invalid literal for int() with base 16: '\x0e\xa3' Python

£可爱£侵袭症+ 提交于 2019-12-29 05:37:04
问题 I get bytes from the serial port which represents the voltage on my PIC board. But I can't convert these bytes(strings) to decimal because I get the error message above. Here is the function(in fact, it's associated with tkinter button) def channel8(): ser.write(chr(0xFF)) print "you have select channel8" x=ser.read(2) w=int(x, 16) print w print "Voltage on channel8 is:" , x ValueError: invalid literal for int() with base 16: '\x0e\xa3' def channel8(): ser.write(chr(0xFF)) print "you have

java- how to generate a random hexadecimal value within specified range of values

时光怂恿深爱的人放手 提交于 2019-12-29 05:17:49
问题 I have a scenario in a java web app, where a random hexadecimal value has to be generated. This value should be within a range of values specified by me. (The range of values can be hexadecimal or integer values). What is the most efficient way to do this> Do I have to generate a random decimal number, and then convert it to hexadecimal? Or can a value be directly generated? 回答1: Yes, you just generate a decimal value in your range. Something such as: Random rand = new Random(); int