Calculation of two fields in ASP.NET (Visual Basic) - asp.net

I have two money fields in a SQL database called TotalClaimed and PartialSettlementAmountRecd.
They are declared as Decimals like so:
Public PartialSettlementAmountRecd As Decimal
Public TotalClaimed As Decimal
They both output the repsective amounts perfectly. I need to do a calculation on them, by subtracting PartialSettlementAmountRecd from TotalClaimed. I have tried the following, but it just outputs a random number, not the amount I require.
Dim NewSettAmount As Decimal = (ClaimDetail.TotalClaimed) - (ClaimDetail.PartialSettlementAmountRecd)
Response.Write("New Settlement Amount: £" & NewSettAmount)
Where am I going wrong? Thanks...

shouldn't it be:
Dim NewSettAmount As Decimal = (ClaimDetail.TotalClaimed) - (ClaimDetail.PartialSettlementAmountRecd)
<>

I need to do a calculation on them, by subtracting PartialSettlementAmountRecd from TotalClaimed
(ClaimDetail.PartialSettlementAmountRecd) - (ClaimDetail.TotalClaimed)
Aren't you doing the opposite of what you want? Aren't you subtracting TotalClaimed From PartialSettlementAmountRecd?

I apologise. The random figures I was getting were due to somebody entering a huge number in the Total Claimed field in the database whilst I was testing without telling me! The code actually works now with sensible figures.

Related

how to create two number sequences

Can we create Purchase order Number Sequence with the division capture for Local and Foreign purchases?
Can we create two number sequence at a time in AX 2012 ?
Yes you can.
Not knowing anything about your version or what you have done or tried, I will try guessing you are using AX 2012.
Then go looking in \Classes\CustPostInvoice\run on how they set the invoiceId variable.
if (countryRegion_LTLV)
{
[invoiceId, voucher] = this.getNumAndVoucher_W(numberSeq);
}
else
{
[invoiceId, voucher] = numberSeq.numAndVoucher();
}
It even looks more ugly, but the point is, use two different number sequences, then use an if to choose the right one.
Maybe you should also read about setting up a new number sequence?

Weird behaviour on Numeric Stepper decimals

I am making an editor for a field with numbers. I tried a text field, but since it's a Number datatype coming in, it didn't go smoothly -- despite recasting strings as numbers etc.. it kept giving me NaN as the value. So I decided it would be best to go with a numeric stepper.
When I initially loaded it up it would drop all my decimals and only display my numbers as integers. I changed the stepIncrement to 0.1 and now it does show the decimals (a weird requirement imo).. but when I step up it occasionally gives me a value like '17.700000000000003' when I would expect 17.7. All of the numbers in my data have a single decimal place. I know I can write a dataformatter, but it seems like it shouldn't be necessary in this situation.
Is there another way I could deal with this?
You've stumbled upon the compromise of trying to represent decimal numbers in floating point binary formats like IEEE 754. Not all decimal numbers can be exactly represented. You can read up on this issue in great detail here:
http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding
You can use Number.toFixed(fractionDigits:uint) to display to an arbitrary number of decimal places.
You can use the valueFormatFunction which takes the numeric value and formats it to a string. You will need to set explicit widths on your numeric steppers to make they fit though.
in your MXML
<s:NumericStepper valueFormatFunction="stepperFormatter"/>
in your script
protected function stepperFormatter(newValue:Number):String
{
return Math.ceil(newValue).toString()
}

vb.net converting an exponent number to a whole number

How can I convert a number with exponent value (such as 4.775900000000000e+004 ) to return a whole number, such as 47,759 using .net2.0 framework?
FYI, this is a weight category, not currency.
I guess it is a string, you can do int.Parse(s, NumberStyles.AllowExponent);. There might be problems with fractional parts, so use double.Parse, float.Parse or decimal.Parse when appropiate.

Decimal data type in Visual Basic 6.0

I need to do calculations (division or multiplication) with very large numbers. Currently I am using Double and getting the value round off problems. I can do the same calculations accurately on C# using Decimal type. I am looking for a method to do accurate calculations in VB6.0 and I couldn't find a Decimal type in VB6.0.
What is the data type used for doing arithmetic calculations with large values and without getting floating point round off problems?
Depending on your data type, you can always use Currency, which is like Decimal(19,4), or 15 digits to the left of the decimal point, and 4 to the right.
In VB6, try using the variant datatype, and casting your numbers to that using CDec, as in:
Dim myDec As Variant
myDec = CDec(1.234)
See if that works.

show decimal or double with zeros

i get price values from DB.
now whenever the price is perhaps 5, I want to show 5.00
if its 4.3 it should be 4.30.
how to convert that?
thanks
You can use the string format for decimal to apply this formatting.
YourDecimal.ToString("#,##0.00");
this should show 5.00, and 4.30.
Also it will show 1,234.56 groupings.
What data types do you use to store the price? It's a bad idea to store prices using floating point numbers because of precision issues. A fixed point number like a decimal is a better idea.
Once you're settled on a data type, you can use string formatting to display it correctly. See MSDN.
yourDecimal.ToString("N2") will also do the same
I never wrote a single line in Asp.net
but simple search in google gave me this :
https://web.archive.org/web/20210928015431/http://www.4guysfromrolla.com/aspfaqs/ShowFAQ.asp?FAQID=181
http://msdn.microsoft.com/en-us/library/dwhawy9k%28VS.71%29.aspx

Resources