1
I have a field, which in the model was like float
, and that’s how you got saved, and you already have data in those columns.
But what happens is that now I need 6 decimal places after the comma. Example: 10.023568
But with the float
that’s not possible, or so far I haven’t been able to figure out any way to do it.
I thought of changing from float
for decimal
, but when I file for change:
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<decimal>(
name: "ValorTotalPedido",
table: "PedidoFornecedor",
type: "decimal(10,6)",
nullable: false,
oldClrType: typeof(float));
migrationBuilder.AlterColumn<decimal>(
name: "ValorProdutos",
table: "PedidoFornecedor",
type: "decimal(10,6)",
nullable: false,
oldClrType: typeof(float));
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<float>(
name: "ValorTotalPedido",
table: "PedidoFornecedor",
nullable: false,
oldClrType: typeof(decimal),
oldType: "decimal(10,6)");
migrationBuilder.AlterColumn<float>(
name: "ValorProdutos",
table: "PedidoFornecedor",
nullable: false,
oldClrType: typeof(decimal),
oldType: "decimal(10,6)");
}
But when will I perform the update-database
he returns me Arithmetic overflow error when converting real to Numeric data type.
I tried to change only mine ViewModel
, but still saved with only two boxes 10.02.
In my Model
the field is like this public float ValorTotalPedido { get; set; }
I tried to put it like this on ViewModel
public decimal ValorTotalPedido { get; set; }
Already tried using parseFloat to convert integer to real
– luiz gustavo
@luizgustavo already yes, and did not solve my problem.
– Mariana
Try to create an auxiliary column with the decimal type, transfer all value in it, and then delete the field of type float, save the update, then you can create the field with the decimal type and transfer the auxiliary field to it, and delete in the auxiliary field.
– Joy Peter