1
Personal I have to save 3 decimal places in my database SQLSERVER, however this saving only 2 houses for example I have a value 0.456 and when saving is 0.450 in the code :
using System.ComponentModel.DataAnnotations;
public class TB_ItensPedidoCompra
{
public decimal ValorUnitario{ get; set; }
[MaxLength(10)]
public string TipoSelecionado { get; set; }
}
In my bank layer it’s like this:
bdProduto.ValorUnitario = Convert.ToDecimal(vlUnitario);
the value up to vlUnitario
enough 0.456
, but when saved is 0.450
Could someone help me
in my bank edited
Nome da coluna = ValorUnitario Tipo de Dados = decimal(18, 4)
How is persistence being made in the database? Insert, Procedure... is using what in the data layer? ADO, EF, NHIBERNATE, etc...
– Roberto Braga
I am using EF and saved context.Savechanges();
– Denilson Carlos
If I changed the guy to Double it wouldn’t work?
– Natan Barros
Apparently the 2 digit accuracy is the standard in EF. See link
https://storiknow.com/entity-framework-decimal-scale-and-precision-convention/
which presents a solution to the same situation you are facing. Basically, create a new class of the attribute type, add it in the construction of Dbcontext inOnModelCreating
and decorate the property (Valorunitario) of your object.– Roberto Braga
@Natanbarros and why he would do something so wrong?
– Maniero
It didn’t work I’m not managing to decorate the property (Valorunitario)
– Denilson Carlos
@Maniero It was just a question, if you’re wrong, explain why... I didn’t think your criticism was bad, but if you’re going to criticize a person who probably knows less than you explain... I said this because when I stopped using decimal and used double in my program it worked...
– Natan Barros
I also asked only one question. https://answall.com/q/219211/101
– Maniero
A question saying it is something wrong (in question format, which was ironic)...I even posted in the comments to see someone correct me if it was wrong, but I expected arguments, thank you for your reply.
– Natan Barros
@Natanbarros I changed my variable to float and solved the problem, I thought I had a way to use the decimal most really have no thanks for the help
– Denilson Carlos
@Denilsonana For nothing...
– Natan Barros