Click here to Skip to main content
15,886,963 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
Richard Deeming2-Jun-16 2:11
mveRichard Deeming2-Jun-16 2:11 
AnswerRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
OriginalGriff2-Jun-16 4:08
mveOriginalGriff2-Jun-16 4:08 
GeneralRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
Richard MacCutchan2-Jun-16 4:35
mveRichard MacCutchan2-Jun-16 4:35 
GeneralRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
OriginalGriff2-Jun-16 4:57
mveOriginalGriff2-Jun-16 4:57 
GeneralRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
Pete O'Hanlon2-Jun-16 5:37
mvePete O'Hanlon2-Jun-16 5:37 
GeneralRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
OriginalGriff2-Jun-16 6:05
mveOriginalGriff2-Jun-16 6:05 
GeneralRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
Mycroft Holmes2-Jun-16 13:03
professionalMycroft Holmes2-Jun-16 13:03 
AnswerRe: How to convert pounds(Lb) to ounce(Oz) and Ounce(Oz) to Pounds(Lb) in C#.Net code Pin
Gerry Schmitz2-Jun-16 4:58
mveGerry Schmitz2-Jun-16 4:58 
If you are really "working on unit of measure", you should take a moment to consider the longer term; e.g. a "weight structure / class".

The weight could have a "native" value, but would have methods for returning different UOMs: all ounces or grams; or pound / kilogram fractions; etc.
C#
public class MyWeight {

   public decimal Weight { get; set; }
   public UnitOfMeasure Units { get; set; }

   public MyWeight( decimal weight, UnitOfMeasure units = UnitOfMeasure.Pounds ) {
      this.Weight = weight;
      this.Units = units;
   }

   public decimal InPounds( int decimalPlaces = 0 ) {

      decimal qty = 0M;

      switch ( this.Units ) {
         case UnitOfMeasure.Pounds:
            qty = Weight;
            break;
         case UnitOfMeasure.Ounces:
            qty = Weight * 0.0625M;
            break;
         case UnitOfMeasure.Kilograms:
            qty = Weight * 2.20462M;
            break;
         case UnitOfMeasure.Grams:
            qty = Weight * 0.00220462M;
            break;
         default:
            throw new NotImplementedException( string.Format( "{0} to Pounds.", Units ) );
      }  // end switch:

      qty = RoundUp( qty, decimalPlaces );

      return qty;
   }

   // Etc.


modified 2-Jun-16 11:09am.

Questionplz introduce appropriate component Pin
Member 125609791-Jun-16 22:15
Member 125609791-Jun-16 22:15 
AnswerRe: plz introduce appropriate component Pin
OriginalGriff1-Jun-16 23:07
mveOriginalGriff1-Jun-16 23:07 
AnswerRe: plz introduce appropriate component Pin
Gerry Schmitz2-Jun-16 5:20
mveGerry Schmitz2-Jun-16 5:20 
AnswerRe: plz introduce appropriate component Pin
Eddy Vluggen3-Jun-16 0:06
professionalEddy Vluggen3-Jun-16 0:06 
QuestionTest Methods Are Grayed out Pin
MadDashCoder1-Jun-16 19:24
MadDashCoder1-Jun-16 19:24 
AnswerRe: Test Methods Are Grayed out Pin
Gerry Schmitz2-Jun-16 5:13
mveGerry Schmitz2-Jun-16 5:13 
QuestionShow message box on top from windows tray application. Pin
raydebojyoti1-Jun-16 0:25
raydebojyoti1-Jun-16 0:25 
AnswerRe: Show message box on top from windows tray application. Pin
OriginalGriff1-Jun-16 1:08
mveOriginalGriff1-Jun-16 1:08 
GeneralRe: Show message box on top from windows tray application. Pin
raydebojyoti1-Jun-16 1:59
raydebojyoti1-Jun-16 1:59 
QuestionHow to find method is implemented Pin
Amit Patel198531-May-16 23:56
Amit Patel198531-May-16 23:56 
AnswerRe: How to find method is implemented Pin
Garth J Lancaster1-Jun-16 0:01
professionalGarth J Lancaster1-Jun-16 0:01 
GeneralRe: How to find method is implemented Pin
Amit Patel19851-Jun-16 20:17
Amit Patel19851-Jun-16 20:17 
AnswerRe: How to find method is implemented Pin
Bernhard Hiller1-Jun-16 4:09
Bernhard Hiller1-Jun-16 4:09 
Questionhow to use jcrop while uploading image Pin
Member 1255141831-May-16 21:00
Member 1255141831-May-16 21:00 
QuestionRe: how to use jcrop while uploading image Pin
Richard MacCutchan31-May-16 21:03
mveRichard MacCutchan31-May-16 21:03 
AnswerRe: how to use jcrop while uploading image Pin
Member 1255141831-May-16 21:10
Member 1255141831-May-16 21:10 
GeneralRe: how to use jcrop while uploading image Pin
Pete O'Hanlon31-May-16 21:20
mvePete O'Hanlon31-May-16 21:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.