I want to represent a price in my model in the form of 0,00. This is the part of my model.
price = models.DecimalField(max_digits=5, decimal_places=2, default=Decimal('0.00'))
However, prices such as 2.10 are still represented as 2.1.
The second issue would be to replace the . with a ,. However default=Decimal('0,00') of course is not possible since , is not a valid literal for Decimal.
Make sure your field in your database state decimal(5,2)
And check out this SO answer regarding replacing the decimal point with a comma.
Related
I am having trouble understanding the values that I have saved in my Round Robin Database. I do a dump with rrdtool dump mydatabase and I get a dump of the data. I found the most recent update, and matched it to my rrd update command:
$rrdupdate --template=var1:var2:var3:var4:var5 N:15834740:839964:247212:156320:13493356
In my dump at the matching timestamp, I find these values:
<!-- 2016-12-01 10:30:00 CST / 1480609800 --> <row><v>9.0950245287e+04</v><v>4.8264158237e+03</v><v>1.4182428703e+03</v><v>8.9785764359e+02</v><v>7.7501969607e+04</v></row>
The first value is supposed to be var1. Out of scientific notation, that's 90,950.245287, which does not match up at all to my input value. (None of them are decimal.)
Is there something special I have to do to be able to convert values from my dump to get the standard value that I entered?
I can't give you specifics for your case, as you have not shown the full definition of your RRD file (internals, DS definition, etc), however...
Values stored in an RRDTool database are subject to Data Normalisation, and are then converted to Rates (unless the DS is of type Gauge in which case they are assumed to be rates already).
Normalisation is when the values are adjusted on a linear basis to make them fit exactly into the time sequence as defined by the Interval (which is often 300 seconds).
If you want to see the values stored exactly as you write them, you need to set the DS type to 'gauge', and make Normalisation a null step. The only way to do the latter is to store the values exactly on a time boundary. So, if the Interval is 300s, then store at 12:00:00, 12:05:00, and so on - otherwise the values will be adjusted.
There is a lot more information about Normalisation - what it is, and why it is done - in Alex van den Bogaerdt's tutorial
I am trying to loop through Column Values inside my Table.
I have a register form, which provides the user with UNIQUE ID, based uppon his information.
For example:
Country = Austria
Each user that selects country Austria will get some sort of Unique Value for that match (lets say 00).
Account ID look like this:
XXXX00UNIQUECODE
Each country has it´s own unique value: (AT = 00, DE = 01, etc)
Now, I want to generate a UNIQUE CODE for each user, that will be just an increment (+1) value of the previous UC value stored in the table, for the same country!
In order to do that, I need to somehow loop through the Column, where the Account IDs are stored and search for the match.
The thing is, when a user tries to generate the UNIQUE CODE, he does not have it yet, so he has only:
XXXX00
Now I need to find all the XXXX00 strings in my AccountID Column, and store them in an Array - then find the Max Value of those and increment it.
BUT I dont know how to search for a part of the string inside a Column of the Table ?
Just the XXXX00 part, not the entire Account ID XXXX00UNIQUECODE.
Agh, I hope you can understand me. It´s quite complicated I know, but I´m really stuck here. Hopefully, someone will know what I mean and maybe even find a smoother solutions for this.
Thanks in advance!
You're pounding a square peg into a round hole. Why not just create a new column called UserID and then you can do:
SELECT Max(UserID) FROM MyTable WHERE Mid(AccountID, 5, 2) = "00"
and increment it by 1.
Better yet, store CountryCode, UserID and the XXXX part in separate fields, and index them. It'll save time when you search or filter, which I'm assume you're going to be doing.
I have the formula:
=DateDiff("yyyy", [DOB], Now())+ Int( Format(now(), "mmdd") < Format( [DOB], "mmdd") )
for calculating age from the [DOB] field in Access
However, when I put this in the Format section on the table in Design view, on enter it changes the text to:
=d"ate"d"iff(yyyy, ["d"OB], "n\ow"())+ I"n"t( For"m"at("n\ow"(), mmdd) < For"m"at( ["d"OB], mmdd) )"
and tells me that it cannot find the field.
Can someone please tell me what is going on?
You cannot use that formula in table design. I would suggest using the form that is bound to the table field you wish to have the information.
Sorry to bring you the bad news but this cannot be achieved at least as a table column,
Also consider the following,
Storing calculated fields in table is not recommended
You would want to enter your formula in the Expression field in the Table design mode
Given you are creating a new calculated field
There are restrictions on which formulas can be used as calculated field, from what I have tried date() or now() cannot be used
I use the following query on the SQL Server 2008 database of a 3rd party product to generate some reports.
SELECT ROUND(SUM(Price),0,1) AS SumNetPrice FROM Transactions
Eg
SUM(Price): 1.2345678
ROUND(SUM(Price),0,1): 1
This has worked fine until now and removed all of the decimal places. In fact curiously the result was truncated even if I didn't specify the 3rd parameter as per the MSDN information http://msdn.microsoft.com/en-us/library/ms175003.aspx on the ROUND function.
The 3rd party company has now changed the data type of the Price column from 'real' to decimal(22, 7). Unfortunately this now means that I always get 7 decimal places even when I use the truncate option of the ROUND function. So now I get:
ROUND(SUM(Price),0,1): 1.0000000
Shouldn't the ROUND(expression,0,1) truncate the result so I don't get any decimal places? How can I remove these decimal places from the result in the SQL query?
In order to make it working the way it worked earlier is to Convert the type from decimal to real. Here is your updated query to get desired output.
select Cast(ROUND(SUM(Price),0,1) as Real) AS SumNetPrice FROM Transactions
SELECT CAST(ROUND(SUM(Price),0,1) AS DECIMAL(22,0)) AS SumNetPrice FROM Transactions
In my cake app user needs to submit mobile number with the registration form, I see that mobile number is automatically encrypted to some other number, how do I not encrypt part of user data ? especially the 10 digit mobile number ?
Since the database field is of type int I'm guessing the issue arises when you try to save phone numbers that are not strictly integers, i.e. +123456, 123 456 789, 00123 456, 123-456-789 etc. You must use a varchar field to store phone numbers that include spaces, hyphens, pluses or start with a zero.