Link to home
Start Free TrialLog in
Avatar of theclassic
theclassicFlag for United States of America

asked on

Asp.Net - Changing number format to display just a value, regardless of negative or positive.

This is a two part question, so I will post the first one...

I have an output where the number is formatted in a currency, and when the value is negative, parenthesis are placed around the asp label that displays the value of the text.  Here is the label tag :

<asp:label id="lblIncreaseInAmountContributingTo401k" runat="server"/>
___________________________________________________________________________
And here is the code where it is called, computed, and formated, I have broken up the code and listed it in order, as I am not sure how far back it is needed to go to aquire the desired result, but this should be enough :

1)

lblIncreaseInAmountContributingTo401k.text = FormatCurrency(Cdbl(hiddenIncreaseInAmountContributingTo401k.text))

____________________________________________________________________________
2)

<asp:label id="hiddenIncreaseInAmountContributingTo401k" runat="server"/>

____________________________________________________________________________
3)

hiddenIncreaseInAmountContributingTo401k.text = Cdbl(hiddenFutureContributionAmount.text) - Cdbl(hiddenCurrentContributionAmount.text)

I am a beginner trying to learn, so thank you for your patience as I learn how to post in the most effective way
Avatar of burakiewicz
burakiewicz
Flag of United States of America image

Math.abs --absolute value
if this returns a number then
lblIncreaseInAmountContributingTo401k.text = Math.abs(FormatCurrency(Cdbl(hiddenIncreaseInAmountContributingTo401k.text)))

ASKER CERTIFIED SOLUTION
Avatar of burakiewicz
burakiewicz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of theclassic

ASKER

That is giving me an error...I actually wont have access to this page untill tommorrow, so I will check back then.  Thank you for your continued help!
That is giving me an error...I actually wont have access to this page untill tommorrow, so I will check back then.  Thank you for your continued help!
Is there a way to just hack it, maybe remove any parenthesis that are in the lable, with jscript?  I have tried a number of different formatting techniques, using VbScript, but keep getting an error, as well as with your code...
you could by using string.Replace or Remove, what happens when you just try this
lblIncreaseInAmountContributingTo401k.text = Math.abs(decimal.Parse(hiddenIncreaseInAmountContributingTo401k.text))

What is the error that you are getting?
let me try again....one sec
The code used is vbscript...isn't this C# ?  Thank you for your patients, I am learning as I go....
It is working, but I only want two decimal places, and I guess I can just use a dollar sign for the text ?
Great, I got it, thank you!  I will post my second question seperately.