Hello folks, I have one here that is really tickling my brain and while it sounds like it should be quite simple, it is becoming increasingly difficult. Here's the skinny. To figure out my vulnerability risk density, I have to take vulnerabilities and divide
that by lines of code. For a simplified example,

500 (vulnerabilities) / 50000 (LOC) = .01 Risk Density or 1%

What I want to do is show this as X vulnerabilities for every Y lines of code (1,000) instead of showing it as a percentage or decimal. Any ideas? Thanks all!

Hello folks, I have one here that is really tickling my brain and while it sounds like it should be quite simple, it is becoming increasingly difficult. Here's the skinny. To figure out my vulnerability risk density, I have to take vulnerabilities and divide
that by lines of code. For a simplified example,

500 (vulnerabilities) / 50000 (LOC) = .01 Risk Density or 1%

What I want to do is show this as X vulnerabilities for every Y lines of code (1,000) instead of showing it as a percentage or decimal. Any ideas? Thanks all!

1% can be written as 10/1000.

Or if you want to go from 500/50,000 to X/1,000 then divide by 50. ie. 50,000 / 50 = 1000 and 500 / 50 = 10. To find 50, the equation is 50,000 = 1000 * X.

Ok, that makes sense. In the c# code behind, is there some way to determine what that multiplier value would be? Here's a real example of what I'm trying to show:

Project

Issue Count

Lines of Code

Risk Density (RD) (Vuln/LOC)

Math Calculation (Issues/LOC = RD * Multiplier)

App1

867

2795641

3/10000

867/2795641 = .0003 * 10000 = 3 / 10000

App2

603

1411731

3/1000

603/1411731 = .0004 * 10000 = 4 / 10000

App3

330

40900

4/100

330/40900 = .004 * 1000 = 8 / 1000

App4

299

48103

2/100

299/48103 = .006 * 1000 = 6 / 1000

App5

212

242261

6/1000

212/242261 = .0008 * 10000 = 8 / 10000

How would one go about determining the multiplier in code? The result of the RD is easy enough, the tricky part from my perspective is determining what that second value would be.

How would one go about determining the multiplier in code? The result of the RD is easy enough, the tricky part from my perspective is determining what that second value would be.

Your math is incorrect. I'm not sure if that's causing issues.

You are trying to figure out where the decimal place is located?

Yes, so if my result is .0008 from division, I need to determine the multiplier value, in this case, .0008 needs to be multiplied by 10,000. In other cases, if my result is .02 then multiply by 100 for example. How do I do that?

Yes, so if my result is .0008 from division, I need to determine the multiplier value, in this case, .0008 needs to be multiplied by 10,000. In other cases, if my result is .02 then multiply by 100 for example. How do I do that?

A loop, a counter, and a condition.

DECLARE @v DECIMAL(7,6)
DECLARE @tenths INT = 0
SET @v = 0.0008
WHILE (@v < 1)
BEGIN
SET @tenths = @tenths + 1
SET @v = @V * 10
END
SELECT @tenths

All-Star

35208 Points

9948 Posts

Moderator

## Converting in C# from decimal to x of y

Jan 06, 2020 03:16 PM|bbcompent1|LINK

Hello folks, I have one here that is really tickling my brain and while it sounds like it should be quite simple, it is becoming increasingly difficult. Here's the skinny. To figure out my vulnerability risk density, I have to take vulnerabilities and divide that by lines of code. For a simplified example,

500 (vulnerabilities) / 50000 (LOC) = .01 Risk Density or 1%

What I want to do is show this as X vulnerabilities for every Y lines of code (1,000) instead of showing it as a percentage or decimal. Any ideas? Thanks all!

Mark as answer posts that helped you.All-Star

44851 Points

19385 Posts

## Re: Converting in C# from decimal to x of y

Jan 06, 2020 03:23 PM|mgebhard|LINK

1% can be written as 10/1000.

Or if you want to go from 500/50,000 to X/1,000 then divide by 50. ie. 50,000 / 50 = 1000 and 500 / 50 = 10. To find 50, the equation is 50,000 = 1000 * X.

Or

X= 50,000 / 1,000

All-Star

35208 Points

9948 Posts

Moderator

## Re: Converting in C# from decimal to x of y

Jan 06, 2020 03:29 PM|bbcompent1|LINK

Ok, I'll play around with that and try generating that as a code-based solution. Thank you.

Mark as answer posts that helped you.All-Star

44851 Points

19385 Posts

## Re: Converting in C# from decimal to x of y

Jan 06, 2020 03:36 PM|mgebhard|LINK

The easiest solution is multiplying the decimal value by 1000. (0.01 * 1,000) = 10 / 1000

Be mindful of significant figures.

All-Star

35208 Points

9948 Posts

Moderator

## Re: Converting in C# from decimal to x of y

Jan 08, 2020 01:03 PM|bbcompent1|LINK

Ok, that makes sense. In the c# code behind, is there some way to determine what that multiplier value would be? Here's a real example of what I'm trying to show:

How would one go about determining the multiplier in code? The result of the RD is easy enough, the tricky part from my perspective is determining what that second value would be.

Mark as answer posts that helped you.All-Star

44851 Points

19385 Posts

## Re: Converting in C# from decimal to x of y

Jan 08, 2020 01:36 PM|mgebhard|LINK

Your math is incorrect. I'm not sure if that's causing issues.

You are trying to figure out where the decimal place is located?

All-Star

35208 Points

9948 Posts

Moderator

## Re: Converting in C# from decimal to x of y

Jan 08, 2020 01:50 PM|bbcompent1|LINK

Actually, that would be 330/40900 = .0008

.0008 * 10000 = 8/10000 = 4/5000 = 1/2500

Yes, so if my result is .0008 from division, I need to determine the multiplier value, in this case, .0008 needs to be multiplied by 10,000. In other cases, if my result is .02 then multiply by 100 for example. How do I do that?

Mark as answer posts that helped you.All-Star

44851 Points

19385 Posts

## Re: Converting in C# from decimal to x of y

Jan 08, 2020 02:05 PM|mgebhard|LINK

A loop, a counter, and a condition.

All-Star

44851 Points

19385 Posts

## Re: Converting in C# from decimal to x of y

Jan 08, 2020 03:12 PM|mgebhard|LINK

I forgot to add the multiplier value can be found by...