This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

I have a string that contains only numeric values. ie. "32.45"

I need to convert it into a decimal.

Then I need to multiply the decimal by 0.8

Finally I need to convert the result to an integer.

psuedocode

// convert the string to a decimal

decimal decConverted = Converted ("32.45");

// multiply the decimal by 0.8

decimal decConverted = Converted(0.8 * decConverted)

convert the resulting decimal to an integer.

int16 intFinal = Converted(decConverted)

What is the proper syntax?

Thanks,

I need to convert it into a decimal.

Then I need to multiply the decimal by 0.8

Finally I need to convert the result to an integer.

psuedocode

// convert the string to a decimal

decimal decConverted = Converted ("32.45");

// multiply the decimal by 0.8

decimal decConverted = Converted(0.8 * decConverted)

convert the resulting decimal to an integer.

int16 intFinal = Converted(decConverted)

What is the proper syntax?

Thanks,

Bear in mind that you will lose everything after the decimal point when you convert it back to int.

```
decimal a = 0;
string str = "32.45";
int result = 0;
a = decimal.Parse(str) * .8;
result = (int)a;
```

double d = Convert.ToDouble(s.ToStrin

Int16 intFinal = Convert.ToInt16(d * 0.08);

string s = "32.45";

s = s + "m";

decimal d = Convert.ToDecimal(s.ToStri

Int16 intFinal = Convert.ToInt16(d * 0.08m);

string str = "32.45";

double dub = Double.Parse(str);

Int16 inVar = new Int16();

inVar = (Int16) dub;

```
decimal a = 0;
string str = "32.45";
int result = 0;
a = decimal.Parse(str) * (decimal).8;
result = (int)a;
```

use this :-

string str = "32.45";

double dub = Double.Parse(str);

dub=dub * 0.8;

Int16 inVar = new Int16();

inVar = (Int16) dub;

I Think it will done by following...

string str = "32.45";

decimal dec = Convert.ToDecimal(str);

dec = dec * Convert.ToDecimal(0.8);

int result = Convert.ToInt32(dec);

```
/// <summary>
/// Parses the input and returns 80% of it rounded to an integer
/// </summary>
/// <param name="text">A formatted number</param>
/// <param name="nearest">Should it round to the nearest integer. Otherwise, it rounds down.</param>
/// <returns>80% of the input text</returns>
public Int32 Calculate(string text, bool nearest)
{
decimal d;
if (!Decimal.TryParse(text, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out d)) // copes with currency formatting, commas etc.
throw new FormatException("Input must be a valid Decimal: " + text);
decimal md = d * 0.8M;
if (nearest)
md = Decimal.Round(md); // round to nearest integer value
return Convert.ToInt32(md);
}
```

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

// convert the string to a decimal

decimal decConverted = Convert.ToDecimal ("32.45");

// multiply the decimal by 0.8;

decimal decConverted = 0.8 * decConverted;

convert the resulting decimal to an integer.

int16 intFinal = Convert.ToInt16(decConvert