Coder Social home page Coder Social logo

Comments (7)

AltruCoder avatar AltruCoder commented on June 27, 2024

Can you provide a fully working example that outputs the double value with a prepended ' ? The following works fine for me, with no prepended '

void Main()
{
	var values = new List<Foo>{
		new Foo { Id = 1, DoubleValue = 48.897736484133866 },
		new Foo { Id = 2, DoubleValue = 0.1000294643384941 },
	};
	var csv = new CsvWriter(Console.Out, CultureInfo.InvariantCulture);
	csv.WriteRecords(values);
}

public class Foo
{
	public int Id { get; set; }
	public double DoubleValue { get; set; }
}

from csvhelper.

JackMcBride98 avatar JackMcBride98 commented on June 27, 2024
void Main()
{
    await using var memoryStream = new MemoryStream();
    await using var streamWriter = new StreamWriter(memoryStream);
    using var csvWriter = new CsvWriter(streamWriter, CultureInfo.InvariantCulture);
    csvWriter.Configuration.RegisterClassMap<RowMap>();

    var csvRows = new List<Row>() { new Double(1076.5525217894019), new Double(37071.25726283525) } 

    csvWriter.WriteRecords(csvRows);
    await streamWriter.FlushAsync();

     var csvArray = memoryStream.ToArray();
     return new Response(csvArray, "heat-loss.csv");
}

public class Row
{
    public double Double { get; }

    public Row(double double){
        Double = double;
    }
}

public sealed class RowMap : ClassMap<Row>
{
    Map(m => m.Double).Name("Double")
}

I'm sorry if this not quite working (I've got a lot of work to be getting on with today), but this is roughly how it is in our system. We are using v 30.0.1

from csvhelper.

AltruCoder avatar AltruCoder commented on June 27, 2024

I wasn't setup to return new Response so I just wrote the MemoryStream to a FileStream. I still can't recreate the prepended ' that you are getting. There has to be something else going on here.

async void Main()
{
	await using var memoryStream = new MemoryStream();
	await using var streamWriter = new StreamWriter(memoryStream);
	using var csvWriter = new CsvWriter(streamWriter, CultureInfo.InvariantCulture);
	csvWriter.Context.RegisterClassMap<RowMap>();

	var csvRows = new List<Row>() { new Row(1076.5525217894019), new Row(37071.25726283525) };

	csvWriter.WriteRecords(csvRows);
	await streamWriter.FlushAsync();

	using (FileStream file = new FileStream(@"C:\Temp\heat-loss.csv", FileMode.Create, FileAccess.Write))
	{
		memoryStream.WriteTo(file);
	}
}

public class Row
{
	public double Double { get; }

	public Row(double value)
	{
		Double = value;
	}
}

public sealed class RowMap : ClassMap<Row>
{
	public RowMap()
	{
		Map(m => m.Double).Name("Double");
	}	
}

from csvhelper.

ajorkowski avatar ajorkowski commented on June 27, 2024

@AltruCoder Try using a negative value - it is adding the escape character ' because the negative value starts with - (I have a feeling they may be using InjectionOptions = InjectionOptions.Escape)

from csvhelper.

AltruCoder avatar AltruCoder commented on June 27, 2024

@ajorkowski I do see where you can get the ' character if the value is negative and you set InjectionOptions = InjectionOptions.Escape. The problem is @JackMcBride98 made no mention of either of those things being the case.

from csvhelper.

JoshClose avatar JoshClose commented on June 27, 2024

Is this still an issue?

from csvhelper.

JackMcBride98 avatar JackMcBride98 commented on June 27, 2024

Not as far as I'm aware

from csvhelper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.