hello everyone, i have a little problem with decimal, i have a linq but my total returns me a lot of decimals but i only need two, this is my linq
Dim listado = (From a In db.LOG_MuestrasLeatherD _
Join b In db.LOG_MuestrasLeather On a.IDMuestraLeather Equals b.IDMuestraLeather
Join c In db.PROD_Tamaños On a.IDTamaño Equals c.IDTamaño
Join d In db.PROD_Secciones On b.IDSeccion Equals d.IDSeccion _
Where b.IDMuestra_E = idmuestrae
Select New With { _
.IDMuestra_E = b.IDMuestra_E,
.IDMuestraLeather = b.IDMuestraLeather,
.Seccion = d.Seccion,
.Tamaño = c.Tamaño,
.Bancas = b.Bancas,
.Subtramos = b.Subtramos,
.Cantidad = a.Cantidad,
.RollosXBanca = a.RollosXBanca,
.Rollos = a.Rollos,
.Total = (a.Rollos /
(From z In db.LOG_MuestrasLeatherD
Where
z.LOG_MuestrasLeather.IDMuestra_E = idmuestrae
Select New With { _
z.Rollos()
}) _
.Sum(Function(p) p.Rollos) * 100)
})
so in the column total i want to return only two decimals
.Total = (a.Rollos /
(From z In db.LOG_MuestrasLeatherD
Where
z.LOG_MuestrasLeather.IDMuestra_E = idmuestrae
Select New With { _
z.Rollos()
}) _
.Sum(Function(p) p.Rollos) * 100)
lvasquez20
0 Points
16 Posts
format total with two decimals in linq
Feb 01, 2013 08:05 PM|LINK
hello everyone, i have a little problem with decimal, i have a linq but my total returns me a lot of decimals but i only need two, this is my linq
Dim listado = (From a In db.LOG_MuestrasLeatherD _ Join b In db.LOG_MuestrasLeather On a.IDMuestraLeather Equals b.IDMuestraLeather Join c In db.PROD_Tamaños On a.IDTamaño Equals c.IDTamaño Join d In db.PROD_Secciones On b.IDSeccion Equals d.IDSeccion _ Where b.IDMuestra_E = idmuestrae Select New With { _ .IDMuestra_E = b.IDMuestra_E, .IDMuestraLeather = b.IDMuestraLeather, .Seccion = d.Seccion, .Tamaño = c.Tamaño, .Bancas = b.Bancas, .Subtramos = b.Subtramos, .Cantidad = a.Cantidad, .RollosXBanca = a.RollosXBanca, .Rollos = a.Rollos, .Total = (a.Rollos / (From z In db.LOG_MuestrasLeatherD Where z.LOG_MuestrasLeather.IDMuestra_E = idmuestrae Select New With { _ z.Rollos() }) _ .Sum(Function(p) p.Rollos) * 100) })so in the column total i want to return only two decimals
.Total = (a.Rollos / (From z In db.LOG_MuestrasLeatherD Where z.LOG_MuestrasLeather.IDMuestra_E = idmuestrae Select New With { _ z.Rollos() }) _ .Sum(Function(p) p.Rollos) * 100)so how i can to do? i appreciate the help
thaicarrot
Contributor
5124 Points
1461 Posts
Re: format total with two decimals in linq
Feb 01, 2013 08:32 PM|LINK
HasPrecision(2,2);
Weera
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: format total with two decimals in linq
Feb 03, 2013 12:40 AM|LINK
Hi,
It's right, for the method you can refer this msdn:
http://msdn.microsoft.com/en-us/library/system.data.entity.modelconfiguration.configuration.decimalpropertyconfiguration.hasprecision(v=vs.103).aspx
And what's more——we can also try to use Math.Round method to cope with that.